-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathZ_Z_C_DeserializationClass.java
More file actions
48 lines (46 loc) · 2.07 KB
/
Z_Z_C_DeserializationClass.java
File metadata and controls
48 lines (46 loc) · 2.07 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
import java.io.*; //Contains Serializable Interface
import java.util.*; //Conatins Scanner
class Emp implements Serializable {
public String name;
public String address;
}
public class Z_Z_C_DeserializationClass {
public static void main(String[] args) throws IOException, ClassNotFoundException {
Emp e = null;
/*************************************************************************
* We Will Create an object that is null as we will store data from file into
* the object in try block
*************************************************************************/
Scanner cin = new Scanner(System.in);
System.out.print("Enter The File Form Where You Want To Retrieve The data:");
String file_name = cin.nextLine();
try {
// Reading the object from a file
FileInputStream file = new FileInputStream(file_name);
ObjectInputStream in = new ObjectInputStream(file);
/*********************************************************************
* As The file will have data of object, we will createte an object of
* ObjectInputStream to read the data from the file and store it in an object
* using readObject method
*********************************************************************/
e = (Emp) in.readObject();
/********************************************************************
* We Will Be Read data with readObject() method and will store it in e object
* of Emp class
********************************************************************/
in.close();
file.close();
/*******************************************************************
* Close Both Input Stream
*******************************************************************/
System.out.println("Name:" + e.name);
System.out.println("Address:" + e.address);
/******************************************************************
* We Will Show all the data That has been retrived from the file
*******************************************************************/
} catch (IOException ex) {
System.out.println("IOException is caught");
}
cin.close();
}
}