Java:-Read from a text file in Java
This code enables you to read from a .txt text file format."C:\\workspace\\newfile.txt" is a sample workspace . Replace path with required path.
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
public class ReadFile {
public static void main(String[] args) {
try {
BufferedReader br= new BufferedReader(new
FileReader("C:\\workspace\\newfile.txt"));
String line;
try {
while((line=br.readLine())!=null){
System.out.println(line);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
No comments:
Post a Comment