meallhour
meallhour

Reputation: 15581

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.

Upvotes: 2

Views: 4843

Answers (1)

user180100
user180100

Reputation:

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.

Upvotes: 5

Related Questions