Jay Kandy
Posts: 77
Nickname: jay
Registered: Mar, 2002
|
|
Re: saving objects on a file
|
Posted: Apr 1, 2002 8:04 AM
|
|
Hmmm.. Let me see if I can explain properly. (To avoid complexity) there are two pairs of abstract classes for performing system input and output through streams, file system and serialization. All classes that provide i/o (except RandomAccessFile) are derived from these abstract classes. They are java.io.InputStream & java.io.OutputStream and java.io.Reader
One simple rule of thumb to remember is: All Writers & Readers read from/write to character streams. All InputStreams & OutputStreams read from/write to byte streams.
Now thats out of the way, guess which classes you would use to do i/o on a File system? Obviously, the pairs:FileWriter & FileReader and FileInputStream & FileOutputStream. Of course you would want to use wrappers around them (BufferedOutputStream).
Now to answer your question, the classes FileOutputStream and FileWriter provide constructors that take a boolean flagging the class to append to the file or not. So you might need something along (using ObjectOutputStream javadoc example):
FileOutputStream ostream = new FileOutputStream("t.tmp", true);
ObjectOutputStream p = new ObjectOutputStream(ostream);
Hope this answered your question.
Sincerely, Jay
|
|