-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathTransientCountry.java
More file actions
63 lines (48 loc) · 1.52 KB
/
TransientCountry.java
File metadata and controls
63 lines (48 loc) · 1.52 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
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
public class TransientCountry {
public static void main(String[] args) throws ClassNotFoundException {
Country india = new Country();
india.setName("India");
india.setPopulation(49089898877l);
try
{
FileOutputStream fileOut = new FileOutputStream("country.ser");
ObjectOutputStream outStream = new ObjectOutputStream(fileOut);
outStream.writeObject(india);
outStream.close();
fileOut.close();
}catch(IOException i)
{
i.printStackTrace();
}
try
{
FileOutputStream fileOut = new FileOutputStream("country.ser");
ObjectOutputStream outStream = new ObjectOutputStream(fileOut);
outStream.writeObject(india);
outStream.close();
fileOut.close();
}catch(IOException i)
{
i.printStackTrace();
}
System.out.println("serialized");
try
{
FileInputStream filein = new FileInputStream("country.ser");
ObjectInputStream outStream = new ObjectInputStream(filein);
Country c1=(Country)outStream.readObject();
outStream.close();
filein.close();
System.out.println(c1.name);
System.out.println(c1.population);
}catch(IOException i)
{
i.printStackTrace();
}
}
}