안드로이드 개발 질문/답변
(글 수 45,052)
public void FileWrite(Informations ifm) throws ClassNotFoundException {
Vector vc = new Vector();
FileInputStream fis = null;
ObjectInputStream ois = null;
BufferedOutputStream bos = null;
ObjectOutputStream oos = null;
FileOutputStream fos = null;
try {
File filec = new File("5215.txt");
if (filec.exists()) {
fis = openFileInput("5215.txt");
ois = new ObjectInputStream(fis);
vc = (Vector) ois.readObject();
ois.close();
} Toast.makeText(this, "sdcard", Toast.LENGTH_SHORT).show();
fos = openFileOutput("5215.txt", MODE_APPEND);
bos = new BufferedOutputStream(fos);
oos = new ObjectOutputStream(new BufferedOutputStream(bos));
vc.add(ifm);
oos.writeObject(vc); } catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Log.i("에러", "에러결국남");
Toast.makeText(this, "fos IOException", Toast.LENGTH_SHORT).show();
} finally {
try {
oos.close();
bos.close();
vc.clear();
fos.close();
Toast.makeText(this, "잘댐", Toast.LENGTH_SHORT).show();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
class Informations implements Serializable {
private Date date;
private double wido;
private double kyengdo;
private static final long serialVersionUID = 1L;
public Informations(){
wido = 1.111;
kyengdo=1.1111;
date = new Date();
}
public Informations(Date date, double wido, double kyengdo)
throws IOException {
this.date = date;
this.wido = wido;
this.kyengdo = kyengdo;
}
}try {
FileInputStream fis = openFileInput("5215.txt");
ObjectInputStream ois = new ObjectInputStream(fis);
vc = (Vector) ois.readObject();
String str=null;
for(int a=0; a<vc.size(); a++){
Informations info = (Informations) vc.elementAt(a);
str = str + info.result();
System.out.println(vc.size());
Log.i("에러1", Integer.toString(vc.size()));
}
show.setText(Integer.toString(vc.size()));
ois.close();
} catch (StreamCorruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}for (int a = 0; a < 2; a++) {
FileWrite(Infos[a]);
}
이런식으로 해서 하는데 Vector 에서 size() 해서 보면 1밖에 없네요.
그리고 FileOutputStream fos = new FileOutputStream("파일이름", true) 하면
IOException 으로 가던데... 왜 그런건가요..?



