Invalid escape sequence (valid ones are \\b \\t \\n \\f \\r \\\" \\' \\\\ )

不羁的心 提交于 2019-11-29 09:28:41

You need to escape the "\" in the file path.

BufferedReader job = new BufferedReader 
               (new FileReader("\\My Documents\\JOBS\\newfile.txt"));

\ is an escape character, use \\

If you're using eclipse, there's a setting that inserts escape chars automatically when pasting:

Window -> Preferences -> Java -> Editor -> Typing -> In String Literals -> Escape text when pasting into a string literal

Then, when something like D:\Env\Images\image1.png is in your clipboard and you paste it into eclipse, it'll automatically look like this: D:\\Env\\Images\\image1.png

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!