J
Jöppl
Gast
Main Klasse, soll das Objekt x speichern:
Die Klasse x (nichts wildes):
Ausgabe:
Ja, klappt nicht - habt ihr eine Idee, wie man koplette Objekte abspeichert?
Code:
package test;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.ObjectOutputStream;
public class Main {
public static void main(String[] args) {
Test x = new Test(123);
FileOutputStream fos;
try {
fos = new FileOutputStream("t.tmp");
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(x);
oos.close();
} catch (Exception e){
e.printStackTrace();}
System.out.println("fertig");
}
}
Die Klasse x (nichts wildes):
Code:
package test;
public class Test {
private int x;
Test(int x){
this.x=x;
}
}
Ausgabe:
Code:
java.io.NotSerializableException: test.Test
at java.io.ObjectOutputStream.writeObject0(Unknown Source)
at java.io.ObjectOutputStream.writeObject(Unknown Source)
at test.Main.main(Main.java:18)
fertig
Ja, klappt nicht - habt ihr eine Idee, wie man koplette Objekte abspeichert?