java

java.io.File.getCanonicalPath(), getAbsolutePath()

알 수 없는 사용자 2008. 3. 5. 11:20
src
String base = "/share/internet/";
String cd = "/a/../b/";
String f = "../a.pdf";
String path = base+cd+f;
String cpath = new File(path).getCanonicalPath();
String apath = new File(path).getAbsolutePath();
println("path = "+path);
println("canonical = "+cpath);
println("absolute = "+apath);

out
path = /share/internet//a/../b/../a.pdf
canonical = D:\share\internet\a.pdf
absolute = D:\share\internet\a\..\b\..\a.pdf