When you write to a BufferedWriter
you are (potentially) writing to an in-memory buffer, and you must flush()
your writes to make sure they reach the disk. close()
would also implicitly call flush()
on any reasonable implementation, but it isn't considered a good practice to rely on it:
public static void main(String[] args) {
String pad = "C:\\Users\\Bernard\\Documents\\Paradox Interactive";
File bestand = new File(pad + "\\test.mod");
BufferedWriter pen = null;
try {
pen = new BufferedWriter(new FileWriter(bestand));
pen.write("line1");
pen.write("line2");
pen.flush();
}catch(IOException e){
// Probably should have some treatment here too
}
finally {
if (pen != null) {
pen.close();
}
}
}