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

PrintWriter output = new PrintWriter(file,true);

When I use PrintWriter(file,true) it's show me error

"no suitable constructor found for PrintWriter(File, boolean)"

how to solve it ,Thanks

Procrastinator
  • 2,526
  • 30
  • 27
  • 36
Waleed
  • 47
  • 3
  • 1
    Have you considered consulting the Javadoc? You can't just make things up and then wonder why they don't exist. – user207421 Sep 29 '17 at 10:54
  • @Tom Possible duplicate how? – user207421 Sep 29 '17 at 10:55
  • @EJP OP _clearly_ wants to instantiate a `PrintWriter` which appends to an existing source and the answers there tell him how to do so. – Tom Sep 29 '17 at 10:56
  • @Tom That is a rather large assumption as the constructors on `PrintWriter` that do take a boolean enable auto-flush. – Mark Rotteveel Sep 30 '17 at 10:26
  • @MarkRotteveel Yes, that's true, but I don't think OP was aiming for that. I could be wrong there, though. So it isn't that "clearly" on second thought. – Tom Sep 30 '17 at 10:30

2 Answers2

1

PrintWriter class doesn't have a constructor that accepts File, Boolean

Your best bet is to remove the Boolean, and just pass the File.

See full list taken from 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. 
achAmháin
  • 4,176
  • 4
  • 17
  • 40
0

PrintWriter class does not have any constructor that take 2 parameter File and boolean together.

So You have to remove boolean parameter.and write code as-

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

PrintWriter output = new PrintWriter(file);
Mostch Romi
  • 531
  • 1
  • 6
  • 19