-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSerial.java
More file actions
43 lines (32 loc) Β· 1019 Bytes
/
Copy pathSerial.java
File metadata and controls
43 lines (32 loc) Β· 1019 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package Chapter7.Day42;
import java.io.*;
public class Serial {
public static void main(String[] args) throws IOException, ClassNotFoundException {
File file = new File("test.txt");
// ObjectOutputStream o = new ObjectOutputStream(new FileOutputStream(file));
// Person p = new MeetCoder("me", 22);
// o.writeObject(p);
ObjectInputStream i = new ObjectInputStream(new FileInputStream(file));
Person p = (Person) i.readObject();
System.out.println(p.getName());
ObjectOutputStream o = new ObjectOutputStream(new FileOutputStream(file));
o.writeObject(p);
}
}
class Person {
public String getName(){
return null;
}
}
class MeetCoder extends Person implements Serializable {
private final String name;
private final int number;
public MeetCoder(String name, int number) {
this.name = name;
this.number = number;
}
@Override
public String getName() {
return name;
}
}