1
|
package serialize;
|
2
|
|
3
|
import java.io.FileOutputStream;
|
4
|
import java.io.ObjectOutputStream;
|
5
|
import java.io.Serializable;
|
6
|
|
7
|
import general.*;
|
8
|
|
9
|
public class Example extends Parent implements Serializable {
|
10
|
|
11
|
private static final long serialVersionUID = 1L;
|
12
|
|
13
|
private int number = 2;
|
14
|
Contain variable = new Contain();
|
15
|
|
16
|
public long getNumber() {
|
17
|
return number;
|
18
|
}
|
19
|
|
20
|
public static void main(String[] args) {
|
21
|
try {
|
22
|
FileOutputStream fos = new FileOutputStream(Constants.SERIALIZED_FILE);
|
23
|
ObjectOutputStream oos = new ObjectOutputStream(fos);
|
24
|
Example s = new Example();
|
25
|
oos.writeObject(s);
|
26
|
oos.flush();
|
27
|
oos.close();
|
28
|
System.out.println("File " + Constants.SERIALIZED_FILE + " created.");
|
29
|
|
30
|
/*
|
31
|
FileInputStream fis = new FileInputStream(Constants.FILE_NAME);
|
32
|
ObjectInputStream ois = new ObjectInputStream(fis);
|
33
|
s = (Example) ois.readObject();
|
34
|
System.out.println("DATA: " + s.string + " " + s.number + " " + Arrays.toString(s.variable.array));
|
35
|
ois.close();
|
36
|
*/
|
37
|
} catch (Exception e) {
|
38
|
e.printStackTrace();
|
39
|
}
|
40
|
}
|
41
|
|
42
|
}
|