-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBankAccountTest.java
More file actions
95 lines (71 loc) · 1.88 KB
/
Copy pathBankAccountTest.java
File metadata and controls
95 lines (71 loc) · 1.88 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
public class BankAccountTest{
public static void main(String[] args) {
StudentDetails obj1 = new StudentDetails("Vedangi", 101);
DemoSer serObj = new DemoSer();
serObj.serialize(obj1);
serObj.deserialize();
}
}
class StudentDetails implements Serializable
{
private String name;
private int rollNo;
public StudentDetails(String name, int rollNo) {
super();
this.name = name;
this.rollNo = rollNo;
}
@Override
public String toString() {
return "StudentDetails [name=" + name + ", rollNo=" + rollNo + "]";
}
}
class DemoSer
{
void serialize(StudentDetails bat)
{
try
{
FileOutputStream fout = new FileOutputStream("C:\\Users\\VBR12\\Desktop\\serializeObject.txt");
System.out.println("File created for writing...");
ObjectOutputStream oos = new ObjectOutputStream(fout);
oos.writeObject(bat);
}
catch(FileNotFoundException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
}
void deserialize()
{
try
{
FileInputStream fin = new FileInputStream("C:\\Users\\VBR12\\Desktop\\serializeObject.txt");
ObjectInputStream ois = new ObjectInputStream(fin);
StudentDetails st = (StudentDetails) ois.readObject();
System.out.println("Object is: "+st);
}
catch(FileNotFoundException e)
{
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}