How does one read/write a file with a serialized object, then some
other data in it, so that after one reads the object, the next byte
read is whatever came after the object in the file? I want to do
something like
Writing:
FileOutputStream fos = new FileOutputStream(myfile);
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(some object);
for(a bunch of bytes) {
fos.write(next byte);
}
Reading:
FileInputStream fis = new FileInputStream(myfile);
ObjectInputStream ois = new ObjectInputStream(fis);
ois.readObject();
while(fis isn't empty) {
fis.readByte();
}
but I am pretty sure that the first call to readByte will go from the
beginning of the file, not after the object like I want it to.
Chris Uppal - 07 Aug 2006 13:13 GMT
> FileInputStream fis = new FileInputStream(myfile);
> ObjectInputStream ois = new ObjectInputStream(fis);
> ois.readObject();
> while(fis isn't empty) {
> fis.readByte();
> }
Don't read() from fis, but from ios -- ObjectInputStream supports the usual
collection of read() methods inherited from InputStream.
-- chris
P.S. Today seems to be IO day ! This is my fifth or sixth posting on the
subject already, and it's only lunchtime...
William Brogden - 07 Aug 2006 15:07 GMT
> How does one read/write a file with a serialized object, then some
> other data in it, so that after one reads the object, the next byte
[quoted text clipped - 7 lines]
> fos.write(next byte);
> }
Just write the byte[] object - fast, simple, and preserves the size of the
array
> Reading:
> FileInputStream fis = new FileInputStream(myfile);
[quoted text clipped - 6 lines]
> but I am pretty sure that the first call to readByte will go from the
> beginning of the file, not after the object like I want it to.