What is the difference between
FileInputStream fstream = new FileInputStream ("file1.txt");
BufferedReader br = new BufferedReader(new InputStreamReader(fstream));
and
FileInputStream fstream = new FileInputStream ("file1.txt");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
Do we really need a DataInputStream here?
The significant thing about the object passed to the InputStreamReader()
constructor is that it will be the object that will bear the weight of any synchronization holds. If you don't want your FileInputStream
to potentially be held up by many calls to it, then the second option is the way to go. See the source of Reader
.