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