Hej NG,
Jeg bliver snart gråhåret
Af en eller anden mystiks grund vil
ObjectInputStream.readObject kun indlæse første object fra stream, selvom
man i det medleverede eksempel kalder serialize. Nogen der kan
gennemskue, hvad der går galt i følgende eksempel:
private void serialize() throws FileNotFoundException, IOException {
//if (object == null)
// throw new IOException("Internal storage is corrupted");
FileOutputStream fos = new FileOutputStream(filename, true);
ObjectOutputStream out = new ObjectOutputStream(fos);
String s = "test";
out.writeObject(s);
out.close();
}
private ArrayList<ObjectState> deSerialize()
throws ClassNotFoundException, FileNotFoundException {
FileInputStream fis = new FileInputStream(filename);
ObjectInputStream in = null;
try {
in = new ObjectInputStream(fis);
while (true) {
//list.add((ObjectState) in.readObject());
String s = (String) in.readObject();
System.out.println(s);
}
}
catch (IOException ex) {}
try {
in.close();
File file = new File(filename);
file.deleteOnExit();
}
catch (IOException ex) {}
return list;
}
--
Hilsen/Regards
Michael Rasmussen
http://keyserver.veridis.com:11371/pks/lookup?op=get&search=0xE3E80917