在Java、C/C++、Python中都一样
/(推荐使用)
一个/就行,多几个/也都行
File file = new File("D:/mystring/mypicture/swordartonline.jpg");
File file = new File("D://mystring//mypicture//swordartonline.jpg");
File file = new File("D:///mystring////mypicture///swordartonline.jpg");
\(转义字符)
个数成偶不成奇
File file2=new File("C:\Users\sheep羊\Desktop\01.jpg");//报错
File file2=new File("C:\\Users\\sheep羊\\Desktop\\01.jpg");//ok
File file2=new File("C:\\Users\\\\sheep羊\\\\\\Desktop\\01.jpg");//ok
File file2=new File("C:\\\Users\\sheep羊\\Desktop\\01.jpg");//报错
哪怕在注释中也会报错:
//C:\users 报错,这是因为\u代表十六进制表示,而sers不能表示十六进制,当然\uabcd就行