meallhour meallhour - 1 year ago 103
Java Question

Does PrinterWriter creates a file if it doesn't exists?

I am using

PrintWriter object
file as below:

PrintWriter pwriter = new PrintWriter("abc.txt");

Please let me know if a file name
will be created if it doesn't exist.

I have tried it and it is not creating file. But i want to confirm if it is the expected not to create the file.

Answer Source

From the javadoc:

fileName - The name of the file to use as the destination of this writer. If the file exists then it will be truncated to zero size; otherwise, a new file will be created. The output will be written to the file and is buffered.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download