Using the supportsFileAttributeView method with a class argument - Java File Path IO

Java examples for File Path IO:File Attribute

Description

Using the supportsFileAttributeView method with a class argument

Demo Code

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) {
    try {//from w  w w  . j  a va 2  s.c  om

      Path path = Paths.get("C:/home/docs/users.txt");
      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));
    } catch (IOException ex) {
      System.out.println("Attribute view not supported");
    }
  }
}

Related Tutorials