Java PosixFileAttributes get file attribute

Description

Java PosixFileAttributes get file attribute

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.LinkOption;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.attribute.PosixFileAttributes;

public class Main {

  public static void main(String[] args) throws IOException {
    Path pUnix = Paths.get("/home/user/tmp/Main.txt");

    PosixFileAttributes fa = Files.readAttributes(pUnix, PosixFileAttributes.class, LinkOption.NOFOLLOW_LINKS);
    System.out.println("Creation time " + fa.creationTime());
    System.out.println("File key " + fa.fileKey());
    System.out.println("Is directory? " + fa.isDirectory());
    System.out.println("Is other? " + fa.isOther());
    System.out.println("Is regular file? " + fa.isRegularFile());
    System.out.println("Is symbolic link? " + fa.isSymbolicLink());
    System.out.println("Last access time " + fa.lastAccessTime());
    System.out.println("Last modified time " + fa.lastModifiedTime());
    System.out.println("Size " + fa.size());
  }//from   w w w.j ava 2s. c  o  m
}



PreviousNext

Related