Search code examples
javaarraysjava-ioprintwriter

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 abc.txt 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.


Solution

  • 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.