I am trying to create a GUI where the user fills in TextFields and then the program creates a txt file and writes to it accordingly.
Currently, the program creates the file with specified name, but without writing anything to it(the txt file is blank.) What am I doing wrong?
Code:
try {
File myObj = new File(mNameTF.getText()+".txt");
if (myObj.createNewFile()) {
System.out.println("File created: " + myObj.getName());
FileWriter myWriter = new FileWriter(mNameTF.getText()+".txt");
BufferedWriter bw = new BufferedWriter(myWriter);
bw.write("Movie: " +mNameTF.getText());
bw.newLine();
bw.write("Actors: "+actorsTF.getText());
bw.newLine();
bw.write("Director: "+ dirTF.getText());
bw.newLine();
bw.write("Producer: "+ prodTF.getText());
bw.newLine();
bw.write("Info: "+descriptionTA.getText());
primaryStage.setScene(sceneA);
} else {
System.out.println("File already exists.");
}
} catch (IOException e) {
System.out.println("An error occurred.");
e.printStackTrace();
}