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();
}
}