Constructor of Class java.io.File
does not create file on disk. It is just a abstraction over the file path. The file is created when you write to the file.
When you are creating FileWriter
it calls constructor of FileOutputStream
that calls a sequence of security checks and then invokes:
if (append) {
openAppend(name);
} else {
open(name);
}
Invocation of open()
creates file on disk.
EDIT:
Here is how open()
is defined:
/**
* Opens a file, with the specified name, for writing.
* @param name name of file to be opened
*/
private native void open(String name) throws FileNotFoundException;
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…