Get file Metadata - Java File Path IO

Java examples for File Path IO:File Attribute

Description

Get file Metadata

Demo Code

import java.io.IOException;
import java.nio.file.*;
import java.nio.file.attribute.BasicFileAttributeView;
import java.util.Set;


public class Metadata {
    public static void main(String[] args) {
        FileSystem fs = FileSystems.getDefault();
        Set<String> views = fs.supportedFileAttributeViews();
        for (String view : views) {
            System.out.println(view);
        }//from www .ja v a  2s. c o m

        for (FileStore store : fs.getFileStores()) {
            boolean supported = store
                    .supportsFileAttributeView(BasicFileAttributeView.class);
            System.out.println(supported);
        }
        Path path = Paths.get("CP1", "test.txt");

        try {
            FileStore store = Files.getFileStore(path);
            boolean supported = store.supportsFileAttributeView("basic");
            System.out.println(store.name() + "  " + supported);
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}

Related Tutorials