0

For the project I'm working on I need to locate the iNode/FileID. It is the unique identifier for individual files in the operating system so that I can keep track of them even if they are renamed or moved.

It was recommended that I use BasicFileAttributes::fileKey to find this and it should work perfectly. My problem is that I need to develop this with Java 6 and BasicFileAttributes needs Java 7.

Unfortunately it's simply not an option to use Java 7, so does anyone have any suggestions as to an external library that can provide the same functionality?

It was also mentioned that I could do some scripting with Command Prompt (I'm using Windows 7) to try to locate it.

Thanks for any and all help/suggestions.

justinlav
  • 155
  • 1
  • 3
  • 11
  • I know you have said that you need to use java6 but you should point out to those that are stopping you that java 6 and 7 have already passed end of life and need to be phased out in favour of java 8. – redge Jun 20 '15 at 01:03
  • I couldn't agree more. I wish I had the power to change that, but it's ultimately just not my call and they don't want to update just yet. – justinlav Jun 21 '15 at 02:50

1 Answers1

1

This is the implementation that I came up with:

public static class FileKey {
    private File file;
    public FileKey(File file) {
        this.file=file;
    }

    @Override
    public int hashCode() {
        long res = file.length();
        res+=file.lastModified();
        if(file.isHidden())
            res+=2;
        if(file.isDirectory()) {
            res+=3;
        }
        return (int) res;
    }

    @Override
    public boolean equals(Object dst) {
        if(dst instanceof FileKey) {
            int dstHashCode = ((FileKey) dst).hashCode();
            return dstHashCode == this.hashCode();
        }
        return false;
    }
}

Just use that as the fileKey object.

lqbweb
  • 1,684
  • 3
  • 19
  • 33