0

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?

ebo
  • 2,717
  • 1
  • 27
  • 22
brandon Whe
  • 206
  • 1
  • 14

3 Answers3

8

You need to escape the double-quotes:

bfW.write("System.out.println(\"YOUR NEW PROGRAM IS COMPLETED\");");
M A
  • 71,713
  • 13
  • 134
  • 174
3
bfW.write("System.out.println(\"YOUR NEW PROGRAM IS COMPLETED\");");

So if you want to define a String which contains "", you do it in this way:

String s = "I am a string with \"\"";

s will be:

I am a string with ""
betteroutthanin
  • 7,148
  • 8
  • 29
  • 48
0

You are trying to write what to the file? "YOUR NEW PROGRAM IS COMPLETED"?

Then the code should be:

bfW.write("YOUR NEW PROGRAM IS COMPLETED");
ViniciusPaiva
  • 151
  • 1
  • 13
  • that's not what OP asked. As the title says : *How to write to a File and add "'s and )'s*, OP wants to know how to write " or ) characters – GameDroids Jul 22 '14 at 19:32