-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEmployee.java
55 lines (43 loc) · 1.39 KB
/
Employee.java
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
44
45
46
47
48
49
50
51
52
53
54
55
package Task20;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
public class Employee implements java.io.Serializable {
private int employeeId;
private String name;
public Employee() {
}
public int getEmployeeId() {
return employeeId;
}
public void setEmployeeId(int employeeId) {
this.employeeId = employeeId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public static void main(String[] args) {
try {
Employee employee = new Employee();
employee.setEmployeeId(123);
employee.setName("Imam");
FileOutputStream file = new FileOutputStream("file.txt");
ObjectOutputStream out = new ObjectOutputStream(file);
out.writeObject(employee);
out.flush();
out.close();
System.out.println("Serialization Done");
ObjectInputStream in = new ObjectInputStream(new FileInputStream("file.txt"));
Employee e = (Employee)in.readObject();
System.out.println("Deserialization Done");
System.out.println("ID: " + e.employeeId + ", " + "Name: " + e.name);
}
catch (Exception e) {
System.out.println(e);
}
}
}