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

前端 未结 4 778
臣服心动
臣服心动 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条回答
  •  暖寄归人
    2021-02-14 04:14

    java.nio.file.Files.isSameFile() checks if two filepaths refers to the same file = i.e. both are hardlinks (this is portable for all OS and filesystems (yeah)). This method traverse symbolic links too then you can compare two symbolic links to filenames points to the same inode on unix filesystem/Windows NTFS.

    You can locate (not editable) file duplicates (this same size and content), determines if are soft/hard links then if not - you can save pathname and delete first then create link to second. You can save 50% disk space.

提交回复
热议问题