Java Reference
In-Depth Information
Checking for a File Attribute View Support
Not all file attribute views are supported on all platforms, except the basic view. You can use the
supportsFileAttributeView() method of the FileStore class to check whether a specific file attribute view is
supported by a file store. The method accepts the class reference of the type of the file attribute view you want to check
for support. If the specified file attribute view is supported, it returns true ; otherwise, it returns false . The following
snippet of code shows how to check for file attribute support:
Path path = get a path reference to a file store;
// Get the file store reference for the path
FileStore fs = Files.getFileStore(path);
// Check if POSIX file attribute is supported by the file store
boolean supported = fs.supportsFileAttributeView(PosixFileAttributeView.class);
if (supported) {
System.out.println("POSIX file attribute view is supported.");
}
else {
System.out.println("POSIX file attribute view is not supported.");
}
Listing 10-13 demonstrates how to check if a file store supports a file attribute view. It checks for the file attribute
support for the C: drive on Windows. Please change the file store path in the main() method to check for the
supported file attribute views for the file store. You may get a different output when you run the program.
Listing 10-13. Checking for Supported File Attribute Views by a File Store
// SupportedFileAttribViews.java
package com.jdojo.nio2;
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 SupportedFileAttribViews {
public static void main(String[] args) {
// Use C: as the file store path on Windwos
Path path = Paths.get("C:");
 
Search WWH ::




Custom Search