I'm really new to Java, and I can't write to a file for some reason, my code looks like this:
FileWriter fstream;
try {
fstream = new FileWriter(fileLocation);
BufferedWriter out = new BufferedWriter(fstream);
log.info("test was supposed to be written to the file");
out.write("test");
out.flush();
out.close();
} catch (IOException e) {
log.error("File not created ", e);
}
When I go to the fileLocation, I see my file, but it's empty. My log does say "test was supposed to be written to the file"
What could I be doing wrong here?
Thanks!
UPDATE: My FileLocation variable is a string:
private String fileLocation="/Users/s/out.txt";
I'm using a Mac
finally. Theflush()call is also unnecessary since close already implicitly does that.