I understand that they serve to retrieve basic metadata from a file, but what actually differs from each other?
EDIT: I previously meant that in the following example the 2 interfaces are used interchangeably. Is there any difference at all? besides the fact that in order to access the attributes with the view first you have to call the
BasicFileAttributeView bs = Files.getFileAttributeView(path, BasicFileAttributeView.class); BasicFileAttributes bfa = Files.readAttributes(path, BasicFileAttributes.class);
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.
BasicFileAttributeView bfav = Files.getFileAttributeView( FileSystems.getDefault().getPath("/dev/null"), BasicFileAttributeView.class ); BasicFileAttributes bfa = bfav.readAttributes(); System.out.println(bfa.lastAccessTime());