I have two methods to read Text File In java one using FileReader and Other File InputStream
FileReader fr=new FileReader("C:\\testq\\test.txt");
BufferedReader br=new BufferedReader(fr);
String s;
while((s=br.readLine())!=null){
System.out.println("value are "+s);
}
and Other is
FileInputStream fstream = new FileInputStream("C:\\testnew\\out.text");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
while ((strLine = br.readLine()) != null){
System.out.println (strLine);
}
Though both give me output ...I just want to know which is the best way to do it.
DataInputStream
in your second example isn't contributing anything: the code would work just the same without it. – Spano