It is good programming practice to flush print writers and file output streams when you are finished with them.
You flush a print writer to ensure that any buffered characters are actually written to the stream's destination. You do flushing by using a flush statement:
writer.flush();
You close file output streams to release system resources. You do closing
by using the same sort of close
statement that you use to close
file input streams:
stream.close();