Interfaces are nothing but the signatures they describe. So the difference between these two interfaces are, that they demand methods of other signatures implemented.
If you have a BasicFileAttributeView instance, you can get a BasicFileAttributes using readAttributes()
. If you don't have a BasicFileAttributeView (BFAV) instance, you can get it using Files.getFileAttributeView. It is guaranteed that you can pass BFAV, even if it may not work with every subclass of FileAttributeView.
Example:
BasicFileAttributeView bfav = Files.getFileAttributeView(
FileSystems.getDefault().getPath("/dev/null"),
BasicFileAttributeView.class
);
BasicFileAttributes bfa = bfav.readAttributes();
System.out.println(bfa.lastAccessTime());
- We get the default FileSystem, so that we can use it in the next step.
- We get a Path using the FileSystem, so that we can use it in the next step
- We get the BasicFileAttributeView (which represents the ability to read a BasicFileAttribute) using the Path, so that ...
- We get the BasicFileAttribute using the BasicFileAttributeView, so that ...
- We get the lastAccessTime (a FileTime), ...
- We print it using FileTime::toString