Java NIO - How is Files.isSameFile different from Path.equals

前端 未结 4 786
臣服心动
臣服心动 2021-02-14 03:50

I could not understand how java.nio.file.Files.isSameFile method is different from java.nio.file.Path.equals method.

Could anybody please tell how they are different?

4条回答
  •  -上瘾入骨i
    2021-02-14 04:20

    • if equal() == true then isSameFile() == true
    • if isSameFile() == true, equal() is not always true

    The isSameFile() method first checks if the Path objects are equal in terms of equal(), and if so, it automatically returns true without checking to see if either file exists.

    If the Path object equals() comparison returns false, then it locates each file to which the path refers in the file system and determines if they are the same, throwing a checked IOException if either file does not exist.

提交回复
热议问题