没有为PrintWriter找到合适的构造函数(File,boolean)

时间:2017-09-29 09:57:50

标签: java printwriter

File file = new File("output.txt");

PrintWriter output = new PrintWriter(file,true);

当我使用PrintWriter(file,true)时,它会显示错误

  

"没有为PrintWriter找到合适的构造函数(文件,布尔值)"

如何解决,谢谢

2 个答案:

答案 0 :(得分:1)

PrintWriter类没有接受File, Boolean

的构造函数

您最好的选择是删除Boolean,然后通过File

查看摘自Oracle

的完整列表
PrintWriter(File file) 
Creates a new PrintWriter, without automatic line flushing, with the specified file.

PrintWriter(File file, String csn) 
Creates a new PrintWriter, without automatic line flushing, with the specified file and charset.

PrintWriter(OutputStream out) 
Creates a new PrintWriter, without automatic line flushing, from an existing OutputStream.

PrintWriter(OutputStream out, boolean autoFlush) 
Creates a new PrintWriter from an existing OutputStream.

PrintWriter(String fileName) 
Creates a new PrintWriter, without automatic line flushing, with the specified file name.

PrintWriter(String fileName, String csn) 
Creates a new PrintWriter, without automatic line flushing, with the specified file name and charset.

PrintWriter(Writer out) 
Creates a new PrintWriter, without automatic line flushing.

PrintWriter(Writer out, boolean autoFlush) 
Creates a new PrintWriter. 

答案 1 :(得分:0)

PrintWriter类没有任何构造函数一起使用2参数File和boolean。

所以你必须删除布尔参数并将代码写为 -

File file = new File("output.txt");

PrintWriter output = new PrintWriter(file);