I've following code for writing some string into a file.
String fileToWrite = System.getProperty("user.dir") + "\\testdata\\towrite.txt";
File file = new File(fileToWrite);
String toWrite = "This is to write to a file. Goodbye!";
FileWriter output = new FileWriter(fileToWrite);
BufferedWriter writer = new BufferedWriter(output);
writer.write(toWrite);
But when I open the file, I can see it empty. Means nothing is being written to it. Can you suggest what I'm doing wrong here?