Determine whether a file is a junction (in Windows) or not?

后端 未结 4 1820
囚心锁ツ
囚心锁ツ 2021-02-13 17:47

I\'ve been searching around trying to find a way to determine if a file is a junction or not, and have not found any satisfactory answers.

First thing I tried was:

4条回答
  •  你的背包
    2021-02-13 18:07

    While on Windows a junction's attributes have isSymbolicLink() == false, they have isOther() == true. So you could do something like:

    boolean isWindows = System.getProperty("os.name").toLowerCase().contains("windows")
    BasicFileAttributes attrs = Files.readAttributes(aPath, BasicFileAttributes.class);
    boolean isJunction = isWindows && attrs.isDirectory() && attrs.isOther();
    

提交回复
热议问题