集册 Java实例教程 获取文件元数据

获取文件元数据

欢马劈雪     最近更新时间:2020-01-02 10:19:05

492
获取文件元数据

import java.io.IOException;/* from N o  w  J a v a . c o m - 时  代  Java*/

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

        }


        for (FileStore store : fs.getFileStores()) {

            boolean supported = store

                    .supportsFileAttributeView(BasicFileAttributeView.class);

            System.out.println(supported);/** 来 自 n o w j a v a . c o m**/

        }

        Path path = Paths.get("CP1", "test.txt");


        try {

            FileStore store = Files.getFileStore(path);

            boolean supported = store.supportsFileAttributeV
展开阅读全文