Java IO Tutorial - Java BasicFileAttributeView .readAttributes ()








Syntax

BasicFileAttributeView.readAttributes() has the following syntax.

BasicFileAttributes readAttributes()     throws IOException

Example

In the following code shows how to use BasicFileAttributeView.readAttributes() method.

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.attribute.BasicFileAttributeView;
import java.nio.file.attribute.BasicFileAttributes;
//from w w w.j  a  va 2s  .co m
public class Main {

    public static void main(String[] args) {

        Path path = Paths.get("C:/tutorial/Java/JavaFX", "Topic.txt");

        try {
          BasicFileAttributeView bv = Files.getFileAttributeView(path, BasicFileAttributeView.class);
          BasicFileAttributes ba = bv.readAttributes();
          System.out.println(ba.creationTime());
        } catch (IOException e) {
            System.err.println(e);
        }



    }
}