BufferedReader buf2=new BufferedReader(
new InputStreamReader(new FileInputStream("D:/info.txt")));
Out of these two methods for reading the contents of a file which method is better and why?
BufferedReader buf=new BufferedReader(new FileReader("D:/info.txt"));
Both lines are equivalent; in both cases you’ll get a
BufferedReaderwhich will allow you to read text from the file.A possible advantage of the first approach is that you can change it slightly to specify the character encoding that you want to use for reading the file, for example:
FileReaderdoes not allow you to specify the character encoding and will always use the default character encoding of your platform, which is not always what you want.