package jp03.part0415.study;

import java.io.FileOutputStream;
import java.io.ObjectOutputStream;

public class WriteObjectFile {

 /**
  * @param args
  */
 private ObjectOutputStream oos;
 public WriteObjectFile(){
  try {
   oos = new ObjectOutputStream(new FileOutputStream("MemberInfo.obj"));
  } catch (Exception e) {
   // TODO: handle exception
   e.printStackTrace();
  }
 }
 
 public boolean saveMemberInfoObject(){
  try {
   oos.writeObject(new MemberVO(1, "홍길동"));
   oos.writeObject(new MemberVO(2, "홍길순"));
   oos.flush();
  } catch (Exception e) {
   // TODO: handle exception
   e.printStackTrace();
   return false;
  } finally{
   try{
    oos.close();
   }catch(Exception ex){}
  }
  return true;
 }
 
 public static void main(String[] args) {
  // TODO Auto-generated method stub
  boolean result = new WriteObjectFile().saveMemberInfoObject();
  if(result){
   System.out.println("저장완료");
  }
  else{
   System.out.println("저장실패");
  }
 }
}

'프로그램 > Java & Jsp' 카테고리의 다른 글

StringTokenizer  (0) 2008.08.20
Java IO - (9) -> [ObjectInputStream]  (0) 2008.08.20
Java IO - (7) -> [FileWriter]  (0) 2008.08.20
Java IO - (6) -> [BufferedReader]  (0) 2008.08.20
Java IO - (5) -> [FileReader]  (0) 2008.08.20

+ Recent posts