Java FileStore check if file attribute support PosixFileAttributeView

Description

Java FileStore check if file attribute support PosixFileAttributeView

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.PosixFileAttributeView;
import java.nio.file.attribute.FileAttributeView;

public class Main {
  public static void main(String[] args) {
    Path path = Paths.get("C:/Java_dev");
    try {/*from   w  w w.jav  a2  s.co  m*/
      FileStore fs = Files.getFileStore(path);
      Class<? extends FileAttributeView> attribClass = PosixFileAttributeView.class;
      // Check if the file attribute view is supported
      boolean supported = fs.supportsFileAttributeView(attribClass);

      System.out.format("%s is supported: %s%n", attribClass.getSimpleName(), supported);

    } catch (IOException ex) {
      ex.printStackTrace();
    }
  }
}



PreviousNext

Related