added flush() before closing the FileStreams