Write multiple object in a single file
Hello Everybody
How are you all? I have some little problem. But there is no suitable solution in the internet. My problem:
I want to write multiple object in a single file. But i cant. I can write a single object in the file using writeObject() method. Can any one help me to give a better solution? For your kind consideration my code given below:
public void writeObject ( String fullFilename, Object object )
{
// create the object file
File objectFile = new File(fullFilename);
// generic stream to the file
FileOutputStream outStream;
// stream for objects to the file
ObjectOutputStream objStream;
try
{
// setup a stream to a physical file on the filesystem
outStream = new FileOutputStream ( objectFile );
// attach a stream capable of writing objects to the stream that
// is connected to the file
objStream = new ObjectOutputStream ( outStream );
// write object to file
objStream.writeObject( object );
// close down the streams
objStream.close();
outStream.close();
}
catch ( IOException e )
{
logger.error( "could not write object to file ",e);
}
}
|