سؤال

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.

هل كانت مفيدة؟

المحلول

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());
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top