Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Which class should I use to write into a text file.

 
krishna Karthikk
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everybody, I am chaitanya, I want to write data into a text file. For that I have already used FileOutputStream class. When I was searching over the internet, I came across some examples, where BufferedWriter and FileWriter classes were used.

and one more example, I do not remember this exactly, the code goes like this,

when I executed this code, nothing was outputted to the file. They said that using BufferedOutpueStream we can write data at high rate.

Is it true? can anybody explain me which class to use, or, is there any efficient method than these?

Thank you all in advance.
 
Jelle Klap
Bartender
Posts: 1951
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want to know more about the basics of I/O in Java this would be a good place to start.

In an effort to make this post a little more helpful, and a little less RTFM, the java.io.Reader and java.io.Writer type hierarchies are intended for reading from and writing to character (i.e. 'text') streams in a convenient way. This includes, but is not limited to, file based I/O. The java.io.InputStream and java.io.OutputStream type hierarchies are more generic and suited for reading and writing bytes, which may of may not be character encoded. So these classes are generally not as convenient for reading and writing 'text', but can certainly be used for that purpose. Now, the Buffered* types in both the Reader/Writer and InputStream/OutputStream type hierarchies are inteded to be used as wrapper implementations around another Reader/Writer/InputStream/OutputStream type. They add data buffering to the mix (duh!), which can improve efficiency. The rationale behind that is explained nicely in the tutorial linked above, and I don't want to spoil the surpise...
 
krishna Karthikk
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Klap for the explanation.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic