-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSerializationTest.java
More file actions
34 lines (30 loc) · 1.35 KB
/
SerializationTest.java
File metadata and controls
34 lines (30 loc) · 1.35 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
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;
public class SerializationTest {
public static void main(String[] args) throws IOException, ParseException {
Scanner sc=new Scanner(System.in);
System.out.println("Enter First Name : ");
String name=sc.next();
System.out.println("Enter Date Of Birth(yyyy/MM/dd) : ");
String dob=sc.next();
System.out.println("Enter city : ");
String city=sc.next();
System.out.println("Enter State : ");
String state=sc.next();
System.out.println("Enter PinCode : ");
int pincode=sc.nextInt();
System.out.println("Enter Country : ");
String country=sc.next();
Date dateofbirth=new SimpleDateFormat("yyyy/MM/dd").parse(dob);
// Student student=new Student(name,dob,new Address(city,state,pincode,country));
Student student=new Student(name,dateofbirth,new Address(city,state,pincode,country));
FileOutputStream fileOutputStream=new FileOutputStream("output2.ser");
ObjectOutputStream objectOutputStream=new ObjectOutputStream(fileOutputStream);
objectOutputStream.writeObject(student);
}
}