Skip to content
Advertisement

Detect if 2 paths are hard-linked together

If I have 2 Paths for files, both share the same FileStore, how can I verify with Java 17 whether they are pointing to the same file on disk (are hard-linked)? For Unix-like systems there seems at least to be a way to verify whether a file has other hardlinks (get Hard Link Count in Java), but on Windows/NTFS I haven’t yet found a way to get either information, except of invoking fsutil hardlink list <file-path> and parsing the output. If necessary, a workaround using JNA would also fine for me.

PS: I have already searched Stackoverflow, but only found similar questions for Python or C#.

Advertisement

Answer

Files.isSameFile(path1, path2) checks whether they are hard-linked.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement