Instead of rewrite new file is created
java
Solution
The `FileWriter` class has a constructor that accepts a second boolean argument which specifies whether the writer should use append mode, which will append new content to the end of an existing file.
I would also recommend closing the writer in a `finally` block.
Documentation
BufferedWriter output;
try {
File file = new File("/home/erik/glassfish3/"+selectedMss+".ini");
//Providing true for second argument specifies it should be appended.
output = new BufferedWriter(new FileWriter(file,true));
for(String newline: content){
output.write(newline+"\n");
}
} catch ( IOException e ) {
e.printStackTrace();
}finally{
output.close();
}
Problem
I'm trying to write to a file which is already exists. As far as i have seen on forums this code should rewrite the old file but instead of rewrite it puts the file name into [] brackets and creates a new one. Any idea? ``` try { File file = new File("/home/erik/glassfish3/" + selectedMss + ".ini"); BufferedWriter output = new BufferedWriter(new FileWriter(file)); for (String newline : content) { output.write(newline + "\n"); } output.close(); } catch (IOException e) { e.printStackTrace(); } ```