본문 바로가기

Java Programming

Object Stream 파일 입출력 테스트

336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

package inputOutput;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

public class IOManager {
 public static void main(String[] args) {
  ObjectInputStream in;
  ObjectOutputStream out;

  String name[] = { new String("현재은"), new String("이재영"),
    new String("박지영") };

  String newName[] = null;

  try {
   out = new ObjectOutputStream(new FileOutputStream("hello.txt"));
   out.writeObject(name);
   out.close();
  } catch (FileNotFoundException e) {
   e.printStackTrace();
  } catch (IOException e) {
   e.printStackTrace();
  }

  try {
   in = new ObjectInputStream(new FileInputStream("hello.txt"));
   try {
    newName = (String[]) in.readObject();
   } catch (ClassNotFoundException e) {
    e.printStackTrace();
   }
  } catch (FileNotFoundException e) {
   e.printStackTrace();
  } catch (IOException e) {
   e.printStackTrace();
  }
  for (String s : newName) {
   System.out.println(s);
  }
 }
}


흐흐.. 인규형 사랑해요♡