So as the title says, I have a file writer and I want to reuse the program multiple times and saving the text onto a new line in the same text document.
Code:
try {
File password1 = new File("password.txt");
if (password1.createNewFile()) {
System.out.println("File created: " + password1.getName()); //Creates new file and inputs variables
} else {
System.out.println("File already exists:");
}
} catch (IOException e) {
System.out.println("An error occurred.");
e.printStackTrace();
}
if (save) {
try {
FileWriter myWriter = new FileWriter("password.txt"); //Saves newly created file as a txt
myWriter.write(web + ": " + password);
myWriter.close();
System.out.println("Successfully wrote to the file");
} catch (IOException e) {
System.out.println("An error occurred");
e.printStackTrace();
}
}