-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSerializationApp.java
More file actions
34 lines (28 loc) · 1.09 KB
/
SerializationApp.java
File metadata and controls
34 lines (28 loc) · 1.09 KB
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
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
class Employee implements Serializable {
public String name;
public String profile;
public transient String location;
Employee(String name,String profile , String location){
this.name = name;
this.profile = profile;
this.location = location;
}
}
public class SerializationApp {
public static void main(String[] args) throws IOException, ClassNotFoundException {
Employee e = new Employee("Amresh", "", "Gurugram");
FileOutputStream fo = new FileOutputStream("serialization.txt");
ObjectOutputStream obf = new ObjectOutputStream(fo);
obf.writeObject(e);
FileInputStream fis = new FileInputStream("serialization.txt");
ObjectInputStream ois = new ObjectInputStream(fis);
Employee emp = (Employee) ois.readObject();
System.out.println("✅ Deserialized Employee: " + emp.location);
}
}