建立File时出错,急问!!!!

dingdong1104 2004-03-26 02:47:35
File file=new File("C:\Documents and Settings\Administrator.QING\桌面\wenjian1.txt");

出现错误如下:
"invalid escape character"

请问如何修改?
...全文
108 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
darkdragon1981 2004-03-26
  • 打赏
  • 举报
回复
java文件好像不能放在中文目录里面,就是路径中不能有中文,建议改文件架!
hui3zhihui 2004-03-26
  • 打赏
  • 举报
回复
File file=new File("C:\Documents and Settings\Administrator.QING\桌面\wenjian1.txt");
改成File file=new File("C:/Documents and Settings/Administrator.QING/桌面/wenjian1.txt");
m1923 2004-03-26
  • 打赏
  • 举报
回复
character "\" is special in java,it should be used as such:
String s = "He said:\"I am a Student.\"";
and if you want to use "\" you must write "\\" .

或者用/也可以
Fortune2k1 2004-03-26
  • 打赏
  • 举报
回复
character "\" is special in java,it should be used as such:
String s = "He said:\"I am a Student.\"";
and if you want to use "\" you must write "\\" .
minghuitian 2004-03-26
  • 打赏
  • 举报
回复
如果你的程序是在Windows操作系统下建立文件那么你的文件名应该这样写:
File file = new File("C:\\Documents and Settings\\Administrator.QING\\桌面\\wenjian1.txt");
另外,最好不要用中文的路径;
还有建立文件的时候最好捕捉下面几个异常:
FileNotFoundException和IOException
JetGeng 2004-03-26
  • 打赏
  • 举报
回复
C:\Documents and Settings\Administrator.QING\桌面\wenjian1.txt该目录中包含了"非法"字符,换一个只有英文的目录就可以了,试试看把
Fortune2k1 2004-03-26
  • 打赏
  • 举报
回复
File file=new File("C:\\Documents and Settings\\Administrator.QING\\桌面\\wenjian1.txt");
seaman0916 2004-03-26
  • 打赏
  • 举报
回复
好像是出现中文的问题:(桌面)!

换个目录就可以了!
free111 2004-03-26
  • 打赏
  • 举报
回复
PrintWriter writer = new PrintWriter(new FileOutputStream("c:/myword.txt"), true);
nkwj 2004-03-26
  • 打赏
  • 举报
回复
\改成\\

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧