package ch06_object;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;

public class ObjectIn {

	public static void main(String[] args) throws IOException {
		
		File path = new File("/Users/simpangyo/FinTech_SPG/FileObject");
		
		File mf = new File(path, "unit.txt");

		// 데이터 전송 통로 생성
		
		FileInputStream fis = new FileInputStream(mf);
		BufferedInputStream bis = new BufferedInputStream(fis);
		ObjectInputStream ois = null;
		
		try {
			
			ois = new ObjectInputStream(bis);
			Unit unit = (Unit) ois.readObject();
			System.out.println(unit);
			
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				if(ois != null) ois.close();
			} catch (Exception e2) {
				e2.printStackTrace();
			}
		}
		
		
	}
}
package ch06_object;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;

public class ObjectIn {

	public static void main(String[] args) throws IOException {
		
		File path = new File("/Users/simpangyo/FinTech_SPG/FileObject");
		
		File mf = new File(path, "unit.txt");

		// 데이터 전송 통로 생성
		
		FileInputStream fis = new FileInputStream(mf);
		BufferedInputStream bis = new BufferedInputStream(fis);
		ObjectInputStream ois = null;
		
		try {
			
			ois = new ObjectInputStream(bis);
			Unit unit = (Unit) ois.readObject();
			System.out.println(unit);
			
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				if(ois != null) ois.close();
			} catch (Exception e2) {
				e2.printStackTrace();
			}
		}
		
		
	}
}
package ch06_object;

import java.io.Serializable;

/*
 * 직렬화
 * → 객체정보를 모아서 바이트 형태로 변환.
 */

// 직렬화 자격을 획득하기 위해 'java.io.Serializable' 을 상속.
public class Unit implements Serializable {
	
	// servialVersionUID
	// → 같은 class인지 확인하는 직렬화 식별자. 
	private static final long serialVersionUID = 1L;
	private String id;
	private int lv;
	
	public Unit(String id, int lv) {
		this.id = id;
		this.lv = lv;
	}
	
	public String toString() {
		return "ID : " + id + "  /   LV : " + lv;
	}
}