Java FileStore get operating system supported attribute views

Description

Java FileStore get operating system supported attribute views

import java.io.IOException;
import java.nio.file.FileStore;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.attribute.AclFileAttributeView;
import java.nio.file.attribute.BasicFileAttributeView;
import java.nio.file.attribute.DosFileAttributeView;
import java.nio.file.attribute.FileAttributeView;
import java.nio.file.attribute.FileOwnerAttributeView;
import java.nio.file.attribute.PosixFileAttributeView;
import java.nio.file.attribute.UserDefinedFileAttributeView;

public class Main {

   public static void main(String[] args) {
      Path path = Paths.get("C:/");
      try {/*from   w w w .  jav a 2s . co m*/
         FileStore fileStore = Files.getFileStore(path);
         System.out
               .println("FileAttributeView supported: " + fileStore.supportsFileAttributeView(FileAttributeView.class));
         System.out.println("BasicFileAttributeView supported: "
               + fileStore.supportsFileAttributeView(BasicFileAttributeView.class));
         System.out.println("FileOwnerAttributeView supported: "
               + fileStore.supportsFileAttributeView(FileOwnerAttributeView.class));
         System.out.println(
               "AclFileAttributeView supported: " + fileStore.supportsFileAttributeView(AclFileAttributeView.class));
         System.out.println("PosixFileAttributeView supported: "
               + fileStore.supportsFileAttributeView(PosixFileAttributeView.class));
         System.out.println("UserDefinedFileAttributeView supported: "
               + fileStore.supportsFileAttributeView(UserDefinedFileAttributeView.class));
         System.out.println(
               "DosFileAttributeView supported: " + fileStore.supportsFileAttributeView(DosFileAttributeView.class));

         System.out.println("FileAttributeView supported: " + fileStore.supportsFileAttributeView("file"));
         System.out.println("BasicFileAttributeView supported: " + fileStore.supportsFileAttributeView("basic"));
         System.out.println("FileOwnerAttributeView supported: " + fileStore.supportsFileAttributeView("owner"));
         System.out.println("AclFileAttributeView supported: " + fileStore.supportsFileAttributeView("acl"));
         System.out.println("PosixFileAttributeView supported: " + fileStore.supportsFileAttributeView("posix"));
         System.out.println("UserDefinedFileAttributeView supported: " + fileStore.supportsFileAttributeView("user"));
         System.out.println("DosFileAttributeView supported: " + fileStore.supportsFileAttributeView("dos"));
      } catch (IOException ex) {
         System.out.println("Attribute view not supported");
      }
   }
}



PreviousNext

Related