Reputation: 1129
So I'm using a BufferedWriter and would like to write some text to a text file.
try {
BufferedWriter b = new BufferedWriter(new FileWriter ("/home/usr/Desktop/logger/logs.txt"));
b.write("hello");
} catch (Exception e1) { e1.printStackTrace(); }
For some reason the text document is being created but nothing is being written to it, why is this?
Upvotes: 1
Views: 3330
Reputation: 21961
You need to close BufferedWriter
, or use try-with-resource
BufferedWriter b = new BufferedWriter(
new FileWriter ("/home/usr/Desktop/logger/logs.txt"));
b.write("hello");
//After writing close the resource
b.close();
Upvotes: 3