如何編寫一個存在於FileOutputStream
的文件?當我運行該程序兩次,第二次oos
和fos
是空編寫一個已存在的文件
public class ReadFile {
static FileOutputStream fos = null;
static ObjectOutputStream oos = null;
public static void main(String[] args) throws IOException, ClassNotFoundException {
File f = new File("file.tmp");
if (f.exists()) {
//How to retreive an old oos to can write on old file ?
oos.writeObject("12345");
oos.writeObject("Today");
}
else
{
fos = new FileOutputStream("file.tmp");
oos = new ObjectOutputStream(fos);
}
oos.close();
}
}