How to write a file that exists with FileOutputStream ? When i run two times this program, the second time oos and fos are null
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();
}
}
if you want to append to the file