Question

im writing a little project, that open files or shortcuts. In process I found problem.

Question is simple. How can I get difference btw file or shortcut? What java commands should I use and search for?

Example

if (fileIsShortcut) {
    return variable1;
} else {
    return variable2;
}

I hope you understand my problem.

Was it helpful?

Solution

use this code

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());
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top