java functon 急!!!!!

来源:百度知道 编辑:UC知道 时间:2024/06/08 04:17:17
saveRecord() save all records in the array to the textfile;
clearRecord() function that will delete all from the file ;
restoreRecord() that will restore all records from textfile to the array;

array可以自己随便建一个。

public void saveRecord(ArrayList<Object> date){
ObjectOutputStream oos = null;
try{
oos = new ObjectOutputStream(new FileOutputStream("d:/record.dat")); for (int i = 0; i < date.size(); i++) {
oos.writeObject(date.get(i));
}
oos.flush();
oos.close();
System.out.println("资料存储成功!");
}catch(Exception ec){
System.out.println("资料存储失败!");
ec.printStackTrace();
}
}
clearRecord():写个空字符到record.dat文件就把原来的数据清空了
restoreRecord():用ObjectInputStream就读出来了,没什么好写的了