In fact, FileOutputStream not buffered, so the data is written directly to the file.
The abstract OutputStream defines a flush (empty method) to accommodate the needs of buffered streams as well, so FileOutputStream inherits it.
If you are unsure of the underlying implementation, it is generally recommended that you delete threads before closing them.
In addition, there is a small error in your code:
file = new File("c:/newfile.txt"); fop = new FileOutputStream("c:/newfile.txt");
EDIT:
Regarding the close part of the question:
When you comment out close() , the completion of main() the close method is called by the finalizer (i.e. before the thread gets garbage collected, the JVM thread calls its finalize() method, which in turn calls close() ) but you cannot reasonably rely on the finalizer: you do not own it, and you cannot be sure of its activation.
Again, it's best to call close() explicitly.
source share