Win a copy of OCP Java SE 8 Programmer II Exam Study Guide this week in the OCP forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

What's the diff between these?  RSS feed

 
Sheriff
Posts: 9087
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
BufferedReader br = new BufferedReader( new InputStreamReader( new FileInputStream( "text.txt" ) ) );

BufferedReader in = new BufferedReader( new FileReader( "text.txt" ) );

Are they equivalent? How are they different?
 
Ranch Hand
Posts: 396
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Marilyn,
I'm just a beginer in I/O. so i may not be correct. but what i feel is that we'll use first format when our file text.txt is having binary data ( non unicode ).
while second format will be used if text.txt is having data in unicode .
would request others to correct me.
regards
Deekasha
 
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Marylin,
Actually FileReader extends InputStreamReader and doesn't add any additional fields or methods so, the only real difference is FileReader allows an easier to read implementation.
Hope this helps
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!