I noticed when I want to write some text to a file, it always creates new file. Why is that? Why not 'append' the content? Does anyone have reasonable explanation?
I will demonstrate with super simple program:
try {
FileWriter fileWrite = new FileWriter("a.txt");
fileWrite.write("Aa");
fileWrite.close();
}catch (IOException ioe){
ioe.printStackTrace();
}
try {
FileWriter fileWriter = new FileWriter("a.txt");
fileWriter.write("Bb");
fileWriter.close();
}catch (IOException ioe){
ioe.printStackTrace();
}
Now, what is the content of file 'a.txt'? It is not AaBb as I expected, but Bb. Can someone explain? Why does java behave this way? How can I understand this the easy way? :)