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

后端 未结 4 1803
囚心锁ツ
囚心锁ツ 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 17:56

    With J2SE 1.7 use Java NIO

    /**
    * returns true if the Path is a Windows Junction
    */
    private static boolean isJunction(Path p) {
        boolean isJunction = false;
        try {
            isJunction = (p.compareTo(p.toRealPath()) != 0);
        } catch (IOException e) {
            e.printStackTrace(); // TODO: handleMeProperly
        }
        return isJunction;
    }
    

提交回复
热议问题