Check User-Defined Attributes Supportability - Java File Path IO

Java examples for File Path IO:File Attribute

Description

Check User-Defined Attributes Supportability

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.UserDefinedFileAttributeView;

public class Main {
  public static void main(String[] args) {
    Path path = Paths.get("C:/folder1/folder2/folder4", "test.txt");

    try {/*from w w  w . j av  a 2s  .c o  m*/
      FileStore store = Files.getFileStore(path);
      if (!store.supportsFileAttributeView(UserDefinedFileAttributeView.class)) {
        System.out.println("The user defined attributes are not supported on: "
            + store);
      } else {
        System.out.println("The user defined attributes are supported on: "
            + store);
      }
    } catch (IOException e) {
      System.err.println(e);
    }
  }
}

Result


Related Tutorials