一个神奇的问题,有大神帮忙解释一波吗
代码:String strPath = "/test/";
System.out.println(strPath);
File file = new File(strPath);
System.out.println(file.getCanonicalPath().replaceAll("\\\\", "/"));
控制台输出:
/test/
/test2
String strPath = "/test/"; System.out.println(strPath); File file = new File(strPath); String absolutePath = file.getAbsolutePath(); System.out.println(absolutePath); String canonicalPath = file.getCanonicalPath(); System.out.println(canonicalPath); System.out.println(canonicalPath.replaceAll("\\\\", "/"));
/test/ D:\test D:\test D:/test