-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstudent.java
117 lines (91 loc) · 2.26 KB
/
student.java
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package begin;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.Scanner;
public class student extends admin implements Serializable
{
static Scanner sc=new Scanner(System.in);
private static final long serialVersionUID = 1L;
String name;
int ID;
String DOB;
String password;
int batch;
String branch;
long phone;
String e_mail;
public student()
{
name=null;
ID=0;
DOB=null;
password=null;
batch=0;
branch=null;
phone=0;
e_mail=null;
}
public void input()
{
System.out.print("enter name : ");
this.name=sc.next();
System.out.print("enter id : ");
this.ID=sc.nextInt();
System.out.print("enter dob : ");
this.DOB=sc.next();
System.out.print("enter batch : ");
this.batch=sc.nextInt();
System.out.print("enter branch : ");
this.branch=sc.next();
System.out.print("enter phone : ");
this.phone=sc.nextLong();
System.out.print("enter email : ");
this.e_mail=sc.next();
System.out.print("enter password : ");
this.password=sc.next();
try
{
FileOutputStream fos = new FileOutputStream(new File("C:\\Users\\Dell\\Desktop\\project\\a.txt"),true);
ObjectOutputStream oos = new ObjectOutputStream(fos);
// write object to file
oos.writeObject(this);
System.out.println("Done");
oos.close();
fos.close();
}
catch (IOException e)
{
e.printStackTrace();
}
finally
{
// sc.close();
}
}
public void output() throws IOException, ClassNotFoundException
{
student s=null;
FileInputStream is = new FileInputStream("C:\\Users\\Dell\\Desktop\\project\\a.txt");
while(is.available()>0)
{
ObjectInputStream ois = new ObjectInputStream(is);
s = (student) ois.readObject();
System.out.print(" name : "+s.name);
System.out.print(" id : "+s.ID);
System.out.print(" dob : "+s.DOB);
System.out.print(" batch : "+s.batch);
System.out.print(" branch : "+s.branch);
System.out.print(" phone : "+s.phone);
System.out.print(" email : "+s.e_mail);
System.out.println();
}
System.out.println();
System.out.println();
is.close();
}
}