【发布时间】:2012-10-25 07:06:36
【问题描述】:
请问如何检测文件是否存在,并且每次运行时不要创建一个新文件。
public static void main(String[] args) throws IOException, ClassNotFoundException {
FileOutputStream fos = new FileOutputStream("file.tmp");
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject("12345");
oos.writeObject("Today");
oos.close();
}
【问题讨论】:
-
如果你看过
File类的文档,你会发现:-File#exists方法。