package CHAPTER13;

import java.io.FileInputStream; // 파일 입력 스트림을 위한 FileInputStream 클래스 가져오기
import java.io.IOException; // 입출력 예외 처리를 위한 IOException 가져오기
import java.io.ObjectInputStream; // 객체 역직렬화를 위한 ObjectInputStream 클래스 가져오기

public class C13_10_DeserializationExample { // 객체 역직렬화 예제 클래스
    public static void main(String[] args) {
        // try-with-resources 문을 사용하여 자동으로 스트림을 닫음
        try (FileInputStream fis = new FileInputStream("person.ser"); // "person.ser" 파일을 읽기 위한 파일 입력 스트림 생성
             ObjectInputStream ois = new ObjectInputStream(fis)) { // 객체 역직렬화를 위한 ObjectInputStream 생성

            Person person = (Person) ois.readObject(); // 파일에서 객체를 역직렬화하여 읽음
            System.out.println("파일에서 읽은 객체: " + person); // 읽은 객체 출력

        } catch (IOException | ClassNotFoundException e) { // 입출력 예외 및 클래스 찾기 실패 예외 처리
            e.printStackTrace(); // 예외 정보 출력
        }
    }
}
