Created
November 17, 2020 22:25
-
-
Save techforum-repo/b5f5481850f6ed2751c4b3e6bfe5ba9c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example; | |
import java.io.FileInputStream; | |
import java.io.FileOutputStream; | |
import java.io.ObjectInputStream; | |
import java.io.ObjectOutputStream; | |
public class SerializationFilter { | |
public static void main(String[] args) throws Exception{ | |
//Serialization | |
Employee emp= new Employee("Test Name","Test Title"); | |
String filename = "employee.ser"; | |
FileOutputStream filewrite = new FileOutputStream(filename); | |
ObjectOutputStream out = new ObjectOutputStream(filewrite); | |
out.writeObject(emp); | |
out.close(); | |
filewrite.close(); | |
//Deserialization | |
FileInputStream fileread = new FileInputStream(filename); | |
ObjectInputStream in = new ObjectInputStream(fileread); | |
Employee empread= (Employee)in.readObject(); | |
System.out.println(empread.name); | |
System.out.println(empread.title); | |
in.close(); | |
fileread.close(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment