如何编写与 存在的文件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();
}
}