forked from kishanrajput23/Programming-Resources
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathObjectInput1.java
More file actions
61 lines (54 loc) · 1.31 KB
/
Copy pathObjectInput1.java
File metadata and controls
61 lines (54 loc) · 1.31 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
import java.io.*;
class Biodata implements Serializable
{
String name;
int age;
String adr1;
String adr2;
Biodata(String nm,int ag,String ad1,String ad2)
{
name=nm;
age=ag;
adr1=ad1;
adr2=ad2;
}
void printbio()
{
System.out.println("Name "+name);
System.out.println("Age "+age);
System.out.println("Address 1 "+adr1);
System.out.println("Address 2 "+adr2);
}
}
public class ObjectInput1
{
public static void main(String[] args) throws EOFException
{
try
{
FileInputStream fis = new FileInputStream("1.tmp");
FileOutputStream fos = new FileOutputStream("1.tmp");
ObjectInputStream ois = new ObjectInputStream(fis);
ObjectOutputStream oos = new ObjectOutputStream (fos);
Biodata b1 = new Biodata("aayush", 35, "Satellite", "india");
Biodata b2 = new Biodata("riddhi", 30, "new jursy", "USA");
Biodata b3 = new Biodata("riya", 40, "moneko", "UK");
oos.writeObject(b1);
oos.writeObject(b2);
oos.writeObject(b3);
System.out.println("--------------------------------");
for (int i=0;i<3;i++)
{
Biodata b;
b = (Biodata) ois.readObject();
b.printbio();
System.out.println("--------------------------------");
}
ois.close();
}
catch (Exception e)
{
System.out.println(e);
}
}
}