JAVA对象流追加
Java的对象流怎么样实现对象追加呢?就是写一个对象进文件,然后结束程序,下次运行再写入一个对象时,将其追加在上一个对象后面。 @Testpublic void testObjectOutputStream(){
ObjectOutputStream oos = null;
try {
//1.
oos = new ObjectOutputStream(new FileOutputStream("object.dat", true));
//2.
oos.writeObject(new String("我爱北京天安门"));
oos.flush();//刷新操作
} catch (IOException e) {
e.printStackTrace();
} finally {
if(oos != null){
//3.
try {
oos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
} @Test
public void testObjectOutputStream(){
ObjectOutputStream oos = null;
try {
//1.
oos = new ObjectOutputStream(new FileOutputStream("object.dat", true));
//2.
oos.writeObject(new String("我爱北京天安门"));
oos.flush();//刷新操作
} catch (IOException e) {
e.printStackTrace();
} finally {
if(oos != null){
//3.
try {
oos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
} 怎么发不了代码呀 就是在写入文件,后面添加一个true就行了
页:
[1]