有没有一种方式可以在Java中将绝对路径缩短为目录。
例如:
./data/../system/bin/ => ./system/bin/
例如:
./data/../system/bin/ => ./system/bin/
是的,使用http://docs.oracle.com/javase/7/docs/api/java/io/File.html#getCanonicalPath()。
File file = new File("C:/Users/../Users");
System.out.println(file.getAbsolutePath()); // C:\Users\..\Users
System.out.println(file.getCanonicalPath()); // C:\Users
if(new File(path).exists()){}
检查文件是否存在。 - MatjažIoException
异常。 - bugybunny
./system/bin/
)。 - Matjaž