很简单的java程序,却错了

来源:百度知道 编辑:UC知道 时间:2024/09/18 17:13:52
import java.io.*;
public class app21
{
public static void main(String args[]) throws IOException
{

FileWriter fw=new FileWriter("c:\\go.txt");
char data[]={'h','e','l','l','o','','j','a','v','a','\r','\n'};
String str=("end of file");
fw.write(data);
fw.write(str);
fw.close();
}
}

书上的一个程序,怎么说错了:
C:\java proc\app21.java:8: empty character literal
char data[]={'h','e','l','l','o','','j','a','v','a','\r','\n'};
^
C:\java proc\app21.java:8: illegal

char data[]={'h','e','l','l','o','','j','a','v','a','\r','\n'};
留意,'o',与,'j'之间的''应该改为' '(中间要加空格)

给你改了一下,可以了
==================================================import java.io.*;
public class app21
{
public static void main(String args[]) throws IOException
{

FileWriter fw=new FileWriter(\"c:\\\\go.txt\");
char data[]={\'h\',\'e\',\'l\',\'l\',\'o\',\'j\',\'a\',\'v\',\'a\',\'\\r\',\'\\n\'};
String str=(\"end of file\");
fw.write(data);
fw.write(str);
fw.close();
}
}