Created
July 10, 2012 15:56
This file contains 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 br.com.ocjp.serializable; | |
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.Date; | |
class Request implements Serializable { | |
public int number; | |
public Date create; | |
public String description; | |
} | |
public class Serialization { | |
public static void main(String[] args) throws IOException, ClassNotFoundException { | |
Request request = new Request(); | |
request.number = 100; | |
request.create = new Date(); | |
request.description = "@@ version 1.3 @@"; | |
FileOutputStream output = new FileOutputStream("C:\\temp\\request.ser"); | |
ObjectOutputStream os = new ObjectOutputStream(output); | |
os.writeObject(request); | |
os.close(); | |
FileInputStream file = new FileInputStream("C:\\Temp\\request.ser"); | |
ObjectInputStream io = new ObjectInputStream(file); | |
Request r = (Request) io.readObject(); | |
System.out.println(r.number); | |
System.out.println(r.create); | |
System.out.println(r.description); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment