• Post Reply Bookmark Topic Watch Topic
  • New Topic

I/O Streams and Readers  RSS feed

 
Vijay Chandran
Ranch Hand
Posts: 186
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear friends,

Is it better to use BufferedInputStream or BufferedReader while reading a file?

There will be a lot of data in the file, like, size will be more than 1 MB.

And which is better to write the data:BufferedOutputStream or BufferedWriter?

Which input and output classes will have better performance?

Kindly provide your help

Regards,
Vijay
 
Rob Spoor
Sheriff
Posts: 20903
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the data is purely character data you should use Reader and Writer.
If the data is binary you should use InputStream and OutputStream.

InputStream and OutputStream can handle character data as well, but they can mess up the encoding. That's why LineNumberInputStream and StringBufferWriter are deprecated.

Readers and Writers can also handle binary data technically (especially when used with InputStreamReader and OutputStreamWriter), but they will return chars and not bytes.
 
Vijay Chandran
Ranch Hand
Posts: 186
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Rob,

Thanks for the reply

Which class's methods are synchronized - InputStreams or Readers?



Regards,
Vijay
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 15865
81
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Whether the methods on streams or readers / writers are synchronized or not is not very interesting. Usually, you do not read or write to one stream from multiple threads at the same time, so there is normally no need for the methods to be synchronized. If you really want to know which methods are synchronized, then you can look that up in the API documentation.

Rob already said what the difference is between readers / writers and input / output streams:

Readers and Writers are for reading and writing text.
Streams are for reading and writing binary data.

Readers and Writers convert the data that they read from or write to an underlying stream to and from text (characters) and perform conversions according to the character encoding that you are using (for example ASCII, UTF-8, ISO-8859-1 etc.).
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!