Equality of attributes of two files

Mark Thornton mthornton at optrak.co.uk
Sun Jul 20 02:27:00 PDT 2008

Rajendra Gutupalli wrote:
> Hi Alan,
> I am looking for a method in BasicFileAttributes such as 'equals() or 
> compareTo' which compares basic file attributes of two files.
> It would be helpful code such as below works:
> BasicFileAttributes ba1 = 
> Attributes.readBasicFileAttributes(file1,false);
> BasicFileAttributes ba2 = 
> Attributes.readBasicFileAttributes(file2,false);
> if (ba1.equals(ba2)){
> S.O.P("Basic File Attributes of two files are same");
> }
> As of now BasicFileAttribute implementation does not seem to override 
> equals method.
> If the implementation has equals or compareTo methods then it is handy 
> for users to compare file attributes of two files without comparing 
> each attribute (like ba1.isDirectory()==ba2.isDirectory() etc.).
> Thanks
> Rajendra.
I'm not sure that you would often want to compare ALL attributes. Last 
access time and perhaps link count are two that you would normally not 
want included in the comparison.

Mark Thornton

More information about the nio-dev mailing list