-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathSerializeInISA.java
More file actions
65 lines (51 loc) · 1.24 KB
/
SerializeInISA.java
File metadata and controls
65 lines (51 loc) · 1.24 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
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
class T implements Serializable
{
int z ;
T(){
z = 1000;
}
}
class Parent implements Serializable
{
String name = new String("Hello");
int x ;
//T obj = new T(); // Has - A
Parent(){
x = 100;
System.out.println("Parent Cons call");
}
}
class Child extends Parent //implements Serializable
{
int y;
Child(){
y = 200;
System.out.println("Child Cons Call");
}
}
public class SerializeInISA {
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
Child obj= new Child();
obj.x = obj.x + 100;
obj.y = obj.y + 200;
String path ="/Users/amit/Documents/TestFileHandlingFeb/ISa.dat";
FileOutputStream fs = new FileOutputStream(path);
ObjectOutputStream os = new ObjectOutputStream(fs);
os.writeObject(obj);
os.close();
fs.close();
System.out.println("Object Write...");
FileInputStream fi = new FileInputStream(path);
ObjectInputStream oi = new ObjectInputStream(fi);
Child ch = (Child)oi.readObject();
System.out.println(ch.x + " "+ch.y+" "+ch.name);
oi.close();
fi.close();
}
}