Java Program to Get the Basic File Attributes Last Updated : 05 Feb, 2021 Summarize Comments Improve Suggest changes Share Like Article Like Report Basic File Attributes are the attributes that are associated with a file in a file system, these attributes are common to many file systems. In order to get the basic file attributes, we have to use the BasicFileAttributes interface. This interface is introduced in 2007 and is a part of the nio package. The basic file attributes contain some information related to files like creation time, last access time, last modified time, size of the file(in bytes), this attributes also tell us that whether the file is regular or not, whether the file is a directory, or whether the file is a symbolic link or whether the file is something is other than a regular file, directory, or symbolic link. Methods that are used to get the basic file attributes are: Return TypeMethod Name And DescriptionFileTimecreationTime() - This method is used to get the creation time of the file.FileTimelastAccessTime() - This method is used to get the last access time of the fileFileTimelastModifiedTime() - This method is used to get the last modified time of the file.longsize() - This method is used to get the size of the file.booleanisDirectory() - This method is used to check whether the file is a directory or not.booleanisSymbolicLink() - This method is used to check whether the file is a symbolic link or not.booleanisRegularFile() - This method is used to check whether the file is regular or not.booleanisOther() - This method is used to check whether the file is something other than a regular file, or directory, or symbolic link.Below is the Java Program to get the basic file attributes: Java // Java Program to get the basic file attributes of the file import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.nio.file.attribute.BasicFileAttributes; import java.sql.Timestamp; import java.util.Date; public class GFG { public static void main(String args[]) throws IOException { // path of the file String path = "C:/Users/elavi/Desktop/GFG_File.txt"; // creating a object of Path class Path file = Paths.get(path); // creating a object of BasicFileAttributes BasicFileAttributes attr = Files.readAttributes( file, BasicFileAttributes.class); System.out.println("creationTime Of File Is = " + attr.creationTime()); System.out.println("lastAccessTime Of File Is = " + attr.lastAccessTime()); System.out.println("lastModifiedTime Of File Is = " + attr.lastModifiedTime()); System.out.println("size Of File Is = " + attr.size()); System.out.println("isRegularFile Of File Is = " + attr.isRegularFile()); System.out.println("isDirectory Of File Is = " + attr.isDirectory()); System.out.println("isOther Of File Is = " + attr.isOther()); System.out.println("isSymbolicLink Of File Is = " + attr.isSymbolicLink()); } } Output:Note: Above Program will run only on system IDE, it will not run on an online IDE. Comment More infoAdvertise with us Next Article Java Program to Get the Creation Time of a File L lavishgarg26 Follow Improve Article Tags : Java Technical Scripter Java Programs Technical Scripter 2020 Java-Files +1 More Practice Tags : Java Similar Reads Java Program to Get the Creation Time of a File Use java.nio package for extracting the creation date and time of any file through java. To extract the date and time of the file use BasicFileAttributes class. java.nio package helps us to get the creation time, last access time, and last modified time, it works for both file and directory. Approac 2 min read Java Program to Implement Attribute API Valid attribute names are case-insensitive, and they are restricted to the ASCII characters in the set of [0-9,a-z, A-Z_-], and cannot be exceeded over 70 characters in length. The attribute's value can contain any characters and will be encoded in UTF-8 when written to the output stream in any prog 6 min read Java Directories Programs: Basic to Advanced Directories are an important part of the file system in Java. They allow you to organize your files into logical groups, and they can also be used to control access to files. In this article, we will discuss some of the Java programs that you can use to work with directories. We will cover how to cr 3 min read Java Program to Create String from Contents of a File A File is a computer resource which is deployed to store different types of data such as text, image, video, to name a few. It is basically a collection of data bound to a single entity. While using your computer, it becomes essential to be able to deal with files and in this article we will be lear 6 min read How to Get the File's Parent Directory in Java? Java is one of the most popular and powerful programming languages. It is widely used for various purposes. In this article, we are going to learn how to find the parent directory of a file or a specified path. Methods to Get the Parent Directory of a fileIn Java, we can get the parent Directory wit 3 min read Java Program to Read a File to String There are multiple ways of writing and reading a text file. This is required while dealing with many applications. There are several ways to read a plain text file in Java e.g. you can use FileReader, BufferedReader or Scanner to read a text file. Given a text file, the task is to read the contents 8 min read Like