summer_soccer
asked on
restore from saved objects?
Hi nice folks,
I'm writing some code relevant to object I/O. The program saves
three objects, a Long, a Vector of some self defined class, and a
Hashset of some self defined class, to a file. Later on it reads
out those objects from the saved file. Problem occurs right here.
It throws out a file.java.io.EOFException when reading the very
first objects. Does anybody have any clue what's wrong here? BTW,
the java compiler is a 1.3 version one. Thanks.
SR
I'm writing some code relevant to object I/O. The program saves
three objects, a Long, a Vector of some self defined class, and a
Hashset of some self defined class, to a file. Later on it reads
out those objects from the saved file. Problem occurs right here.
It throws out a file.java.io.EOFException when reading the very
first objects. Does anybody have any clue what's wrong here? BTW,
the java compiler is a 1.3 version one. Thanks.
SR
If you posted your current code, it might give us a better idea.
Sorry for extra post, Tim just beat me :)
Hee hee :-)
ASKER
Actually it's part of a big package. Actually, now I've tried as follows:
try{
String storedStatesFile = "hoststates-data";
ObjectOutputStream outToStatesFile = new ObjectOutputStream(new FileOutputStream(storedSta tesFile));
outToStatesFile.writeLong( System.cur rentTimeMi llis());
outToStatesFile.close();
ObjectInputStream inFromStatesFile = new ObjectInputStream(new FileInputStream(storedStat esFile));
Long lastSaveTime = inFromStatesFile.readLong( );
}
catch(Exception e) {
System.out.println("Except ion: "+e);
}
The program threw out an EOFException when it tries to readLong from storedStatesFile.
Does anybody have any clue on this? Thanks a lot.
SR
try{
String storedStatesFile = "hoststates-data";
ObjectOutputStream outToStatesFile = new ObjectOutputStream(new FileOutputStream(storedSta
outToStatesFile.writeLong(
outToStatesFile.close();
ObjectInputStream inFromStatesFile = new ObjectInputStream(new FileInputStream(storedStat
Long lastSaveTime = inFromStatesFile.readLong(
}
catch(Exception e) {
System.out.println("Except
}
The program threw out an EOFException when it tries to readLong from storedStatesFile.
Does anybody have any clue on this? Thanks a lot.
SR
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
and don't forget:
inFromStatesFile.close() ;
inFromStatesFile.close() ;
Could try this:
outToStatesFile.writeObjec t(new Long(System.currentTimeMil lis()));
Long lastSaveTime = (Long)inFromStatesFile.rea dObject();
also, inFromStatesFile.readLong( ); returns a 'long' value, not Long.
outToStatesFile.writeObjec
Long lastSaveTime = (Long)inFromStatesFile.rea
also, inFromStatesFile.readLong(
Yeah...like I said ;-)
if that doesnt help (which i am pretty sure IT WILL) see if the object is ever written to the file
No offence, folks, but I'd prefer saving 3 different kinds of objects into 3 different files, or else make another class which would wrap these 3 objects in it, and then write that one to the file.
Cheers,
Mayank.
Cheers,
Mayank.
easy doing that also. save all your objects into a vector and save vector in the file. next time load the vector and cast the elements back to your own objects
Tim your too fast for me ;).
Tim