javafileclassbufferedwriterbuffered

How to write to a File and add "'s and )'s


I'm writing to a file using BufferedWriter and when I enter this code

bfW.write("System.out.println("YOUR NEW PROGRAM IS COMPLETED");");

and it gives me this error:

 File_writer.java:93: error: ';' expected                  
 bfW.write("System.out.println("YOUR NEW PROGRAM IS COMPLETED");");   

How do I fix this?


Solution

  • You need to escape the double-quotes:

    bfW.write("System.out.println(\"YOUR NEW PROGRAM IS COMPLETED\");");