I'm trying to create a program which saves text on a file and then text can be added onto the file. However, every time i try to write to the file, it overwrites it and doesn't write anything. I need it to add whatever information i want it UNDER the rest.
FileReader input;
BufferedReader readFile;
FileWriter output;
BufferedWriter writeFile;
try {
// input = new FileReader(password_file);
//readFile = new BufferedReader(input);
output = new FileWriter(password_file);
writeFile = new BufferedWriter(output);
//while ((temp_user= readFile.readLine()) !=null) {
//temp_pass = readFile.readLine();
//}
temp_user = save_prompt.getText();
temp_pass = final_password;
//Writes to the file
writeFile.write(temp_user);
writeFile.newLine();
writeFile.write(temp_pass);
}
catch(IOException e) {
System.err.println("Error: " + e.getMessage());
}
}
FileWriter(File,append)
&FileWriter(String,append)
. – Ardyth