본문 바로가기

공부/자바

열혈강의 자바 464쪽

반응형

import java.io.*;

class Sub implements Serializable{
 int x;
 int y;
}

public class Mains
{
 public static void main(String[] args) throws IOException
 {
  Sub ap = new Sub();
  ap.x = 100;
  ap.y = 200;
  
  File dir = new File("c:\\java");
  File file = new File(dir, "object.txt");
  FileOutputStream fos = new FileOutputStream(file);
  BufferedOutputStream bos = new BufferedOutputStream(fos);
  ObjectOutputStream oos = new ObjectOutputStream(bos);
  oos.writeObject(ap);
  oos.close();
 }
}

반응형