2017-09-29 8 views
-2
File file = new File("output.txt"); 

PrintWriter output = new PrintWriter(file,true); 

Lorsque j'utilise PrintWriter(file,true) il me marge d'erreur deaucun constructeur approprié trouvé pour PrintWriter (Fichier, Boolean)

"aucun constructeur approprié trouvé pour PrintWriter (Fichier, Boolean)"

comment le résoudre, Merci

+1

Avez-vous envisagé de consulter le Javadoc? Vous ne pouvez pas faire les choses et vous demander pourquoi elles n'existent pas. – EJP

+0

@Tom Copie possible comment? – EJP

+0

@EJP OP _clearly_ veut instancier un 'PrintWriter' qui s'ajoute à une source existante et les réponses lui indiquent comment le faire. – Tom

Répondre

1

PrintWriter classe n'a pas de constructeur qui accepte File, Boolean

Votre meilleur pari est d'enlever le Boolean, et il suffit de passer le File.

Voir la liste complète tirée de 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. 
0

classe PrintWriter n'a pas de constructeur qui prend 2 paramètres et fichiers booléen ensemble.

Vous devez donc supprimer le code d'écriture parameter.and booléen AS-

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

PrintWriter output = new PrintWriter(file);