java - 如果文件不存在,PrinterWriter 是否会创建该文件?

标签 java arrays java-io printwriter

我正在使用 PrintWriter 对象 文件,如下所示:

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

如果文件名 abc.txt 不存在,请告诉我是否会创建该文件。

我已经尝试过了,但它没有创建文件。但我想确认是否预期不创建该文件。

最佳答案

来自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.

关于java - 如果文件不存在,PrinterWriter 是否会创建该文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40276888/

相关文章:

java - contains方法忽略等于重写

java - Android 在未完成 Activity 的情况下执行退出动画

java - 字符串到字节然后 byte[] 0xformat

java - For Loop 保龄球得分

java - 在Java中提取格式化文本文件的特定部分

java - FileInputStream 找不到文件

java - 窗口生成器和 Swing 中的设计时间异常

java - 系统输出,系统错误 : often temporary debugging statements warning

ruby - 将要传递给方法的数组数组分隔为多个对象

java - 在Windows中编辑受UAC保护的文件