Meaningless Drivel is fun!*
The moose likes Beginning Java and the fly likes Which class should I use to write into a text file. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Which class should I use to write into a text file." Watch "Which class should I use to write into a text file." New topic
Author

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

krishna Karthikk
Ranch Hand

Joined: Mar 16, 2010
Posts: 92
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.


There is no rule that we all should know everything. Lets learn few things of everything here.
Jelle Klap
Bartender

Joined: Mar 10, 2008
Posts: 1761
    
    7

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...


Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
krishna Karthikk
Ranch Hand

Joined: Mar 16, 2010
Posts: 92
Thank you Klap for the explanation.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Which class should I use to write into a text file.