我正在编写一个小项目,用于打开文件或快捷方式。过程中发现问题。
问题很简单。 我怎样才能得到不同的 btw 文件或快捷方式?我应该使用和搜索哪些 java 命令?
例子
if (fileIsShortcut) {
return variable1;
} else {
return variable2;
}
我希望你能理解我的问题。
最佳答案
使用此代码
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());
}
关于Java查找文件类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21264888/