Either create your PrintWriter
with this constructor, changing the first argument to an OutputStream
:
out = new PrintWriter(new FileOutputStream("filename.txt"), true);
to turn on auto flushing, or, just close the writer once you're done writing to it with out.close()
.