Monday, January 12, 2009

Symbolic Link?

How to check from Java that file is a symbolic link? (without using external programs or JNI)

At once !file.getCanonicalFile().equals(file) is incorrect.

Answer:



boolean isSymlink(File f) {
File cp = file.getParentFile().getCanonicalFile();
File f1 = new File(cp, f.getName());
return !f1.equals(f1.getCanonicalFile());
}
P. S. For all that, JDK standard library developers are villains, because JDK doesn't provide API to OS-specific functions.

на русском

No comments:

Post a Comment