11. 23. 4. 다각형 Reading Basic Data From an Object Stream 읽기 및 쓰기

import java.awt.Polygon;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

public class ReadBasicData {

	public static void main(String[] args) {
		int[] x = new int[]{1,2,3};
		int[] y = new int[]{4,5,6};
		
		/*
		 *  :
		 * xpoints - X  
		 * ypoints - Y  
		 * npoints -   Polygon   
		 */
		Polygon polygon = new Polygon(x, y, x.length);// 
		
		try{// Object 
			ObjectOutputStream objectOut = new ObjectOutputStream(new BufferedOutputStream(
					new FileOutputStream("Polygon.bin")));//  .bin  
			objectOut.writeObject(polygon);// 
			objectOut.close();
		}catch(IOException e){
			e.printStackTrace();
		}
		
		try{
			ObjectInputStream objectIn = new ObjectInputStream(new BufferedInputStream(
					new FileInputStream("Polygon.bin")));
			Polygon theLine = (Polygon)objectIn.readObject();// Polygon
			System.out.println(theLine);
			objectIn.close();
		}catch(Exception e){
			e.printStackTrace();
		}	
	}
}
/*
 * java.awt.Polygon@1270b73
 */

좋은 웹페이지 즐겨찾기