Check for the supported attribute in Java

Description

The following code shows how to check for the supported attribute.

Example


//from  w w w  . j  a va  2  s .  c o  m
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) throws Exception {
    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));

    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"));
  }
}




















Home »
  Java Tutorial »
    I/O »




Binary File
Byte Array
CharSet
Checksum
Console
Create Copy Move Delete
Directory
Drive
Encode Decode
File Attribute
File Lock
File System
GZIP
Jar File
NIO Buffer
Path
Scanner
StreamTokenizer
Temporary File
Text File
Zip