How to shorten the file path (get the canonical path) in java?

Is there any path in java that can shorten the absolute directory path.

For example:

./data/../system/bin/

=> ./system/bin/

+3


source to share


1 answer


Yes, use 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

      

+5


source







All Articles