Convert a filename path to a unique canonical form suitable for comparisons in Java
Description
The following code shows how to convert a filename path to a unique canonical form suitable for comparisons.
Example
//from w w w .ja v a 2s .c o m
import java.io.File;
public class Main {
public static void main(String[] argv) throws Exception {
File file1 = new File("./filename");
File file2 = new File("filename");
System.out.println(file1.equals(file2));
file1 = file1.getCanonicalFile();
file2 = file2.getCanonicalFile();
System.out.println(file1.equals(file2));
}
}
The code above generates the following result.