//Skip to content
- import java.io.FileInputStream;
- import java.io.FileNotFoundException;
- import java.io.IOException;
- import java.io.ObjectInputStream;
-
- public class DeserializeDemo {
-
- public static void main(String[] args) throws FileNotFoundException, ClassNotFoundException {
-
-
- Employee employee;
- FileInputStream fStream=new FileInputStream("G:/employee.ser");
- try {
- ObjectInputStream oStream=new ObjectInputStream(fStream);
- employee=(Employee)oStream.readObject();
-
-
-
-
- employee.getId();
- employee.getName();
- } catch (IOException e) {
-
- e.printStackTrace();
- }
-
-
-
- }
-
- }
-
-
-
-
- import java.io.Serializable;
-
- public class Employee implements Serializable {
-
-
-
-
-
- transient public int id; //When you don't use transient you get value.....
- transient public String name;
-
- public void getName(){
- System.out.println("Employee name : "+name);
- }
-
- public void getId() {
- System.out.println("Employee id : "+id);
- }
-
- }
I am Md Abdullah Al Hasan. I have completed my graduation in Computer Science and Engineering from Jashore University of Science and Technology.
0 Comments:
Post a Comment