본문 바로가기

안드로이드

객체를 파일로 저장하기 FileOutputStream ObjectOutputStream

FileOutputStream fos = null;
        ObjectOutputStream oos = null;
        
        Vector v = new Vector();
        v.addElement(new String("data 1"));
        
        try{
        fos = new FileOutputStream("filepath");
        oos = new ObjectOutputStream(fos);
        oos.writeObject(v);
        oos.reset();
        }catch (Exception e) {
// TODO: handle exception
}finally{
try{
fos.close();
oos.close();
}catch (Exception e) {
// TODO: handle exception
}
}