• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

I/O Streams and Readers

 
Ranch Hand
Posts: 186
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 22656
126
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear Rob,

Thanks for the reply

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



Regards,
Vijay
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.).
 
You totally ruined the moon. You're gonna hafta pay for that you know. This tiny ad agrees:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic