集册 Java实例教程 查询和设置文件元数据

查询和设置文件元数据

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

526
查询和设置文件元数据
/*NowJava.com*/

import java.io.IOException;

import java.nio.file.FileSystems;

import java.nio.file.Files;

import java.nio.file.Path;

import java.nio.file.attribute.DosFileAttributeView;


public class Main {


  public static void main(String[] args) {

    Path path = FileSystems.getDefault().getPath("./file2.log");

    try {

      System.out.println("File Size:" + Files.size(path));

      System.out.println("Is Directory:" + Files.isDirectory(path));

      System.out.println("Is Regular File:" + Files.isRegularFile(path));

      System.out.println("Is Symbolic Link:" + Files.isSymbolicLink(path));

      System.out.println("Is Hidden:" + Files.isHidden(path));

      System.out.println("Last Modified Time:" + Files.getLastModifiedTime(path));/** from 时代Java公众号 - N o w J a  v a . c o m**/

      System.out.println("Owner:" + Files.getOwner(path));



      DosFileAttributeView view = Files.getFileAttributeView(path,DosFileAttributeView.class);

      System.out.println("\nDOS File Attributes\n------------------------------------\n");

      System.out.println("Archive  :" + view.readAttributes().isArchive());

      System.out.println("Hidden   :" + view.readAttributes().isHidden());

  
展开阅读全文