객체를 바이트 스트림으로 변환하는 과정을 직렬화라고 하며
바이트 스트림을 객체로 변환하는 과정을 역직렬화라고 한다.
Object Byte Stream
writeObject를 사용하여 객체를 ObjectOutputStream에 쓸 때, 이 객체가 참조하는 모든 다른 객체들이 스트림에 쓰여지는 것을 의미
바이트를 readObject 함수를 사용하여 ObjectInputStream에 쓸 때,
예를들어, 나중에 사용하기 위해 HashMap 객체를 파일로 저장한다고 가정해보자. 그러면 당믕과 같이 hashMap으로 시작하는 객체 그래프를 작성할 수 있다.
FileOutputStream fileout = new FileOutputStream("tab");
ObjectOutputStream out = new ObjectOutputStream(fileout);
HashMap<? , ? > hash = getHashMap();
out.writeObject(hash);
FilInputStream filein = new FileInputStream("tab");
ObjectInputStream ois = new ObjectInputStream(filein);
HashMap<?,?> hash = new HashMap();
ois.readObject(hash);
바이트 스트림을 객체로 변환하는 과정을 역직렬화라고 한다.
Object Byte Stream
writeObject를 사용하여 객체를 ObjectOutputStream에 쓸 때, 이 객체가 참조하는 모든 다른 객체들이 스트림에 쓰여지는 것을 의미
바이트를 readObject 함수를 사용하여 ObjectInputStream에 쓸 때,
예를들어, 나중에 사용하기 위해 HashMap 객체를 파일로 저장한다고 가정해보자. 그러면 당믕과 같이 hashMap으로 시작하는 객체 그래프를 작성할 수 있다.
FileOutputStream fileout = new FileOutputStream("tab");
ObjectOutputStream out = new ObjectOutputStream(fileout);
HashMap<? , ? > hash = getHashMap();
out.writeObject(hash);
FilInputStream filein = new FileInputStream("tab");
ObjectInputStream ois = new ObjectInputStream(filein);
HashMap<?,?> hash = new HashMap();
ois.readObject(hash);
'JAVA이야기' 카테고리의 다른 글
맞춤화된 직렬화 (0) | 2011.08.07 |
---|---|
직렬화 가능한 클래스 만들기 (0) | 2011.07.30 |
Data 바이트 스트림 (0) | 2011.07.30 |
StreamTokenizer (0) | 2011.07.30 |
PushBackStream (0) | 2011.07.30 |