Java 1.6 - Determine Symbolic Links

Java 1.6 - determine symbolic links

The technique used in Apache Commons uses the canonical path to the parent directory, not the file itself. I don't think that you can guarantee that a mismatch is due to a symbolic link, but it's a good indication that the file needs special treatment.

This is Apache code (subject to their license), modified for compactness.

public static boolean isSymlink(File file) throws IOException {
if (file == null)
throw new NullPointerException("File must not be null");
File canon;
if (file.getParent() == null) {
canon = file;
} else {
File canonDir = file.getParentFile().getCanonicalFile();
canon = new File(canonDir, file.getName());
}
return !canon.getCanonicalFile().equals(canon.getAbsoluteFile());
}

Detecting a symlink in Java

Also you can use isSymbolicLink(Path path) method. It will be more reliable.

java.io.File file = ...;
boolean isSymbolicLink = Files.isSymbolicLink(file.toPath());

Similar examples from Java Doc 'Detecting a Symbolic Link'.

Java: check symbolic link file existence

looks that way for now... unless you go with openjdk http://openjdk.java.net/projects/nio/javadoc/java/nio/file/attribute/BasicFileAttributes.html#isSymbolicLink()

Detect if a File is a symbolic link in Java 8

Take a look at java.nio.file.attribute.BasicFileAttributes.isSymbolicLink() available since Java 7

How to get java to recognize symbolic links under cygwin

I don't think there is a simple answer to this. As various pages state, Cygwin is an application suite rather than an OS, and Sun does not support Java on Cygwin.

However, it may be possible to build JDK 6 for Cygwin from the source code. Certainly, this page implies that it is possible. Whether this gives you a JDK that understands Cygwin style symbolic links is anyones guess ... :-)

spring-integration-file using java 1.6

This is a bug; the watch service used to be an optional (external) class; it was embedded as an inner class in 4.3 to avoid some configuration issues. A work-around is to drop back to the 4.2.12 version. I opened a JIRA Issue.



Related Topics



Leave a reply



Submit