Provides the state of a file or directory, File attributes at a point in time.

Class Declaration

Following is the declaration for org.apache.commons.io.monitor.FileEntry Class −

  1. public class FileEntry
  2. extends Object implements Serializable

Features

FileEntry class object provides following file attributes at a point in time.

  • getName() − file name.
  • exists() − checks if file exists or not.
  • isDirectory() − checks if file is a directory.
  • lastModified() − gives last modified date time.
  • listFiles() − gives content of directory.

Example of FileEntry Class

Here is the input file we need to parse −

  1. Welcome to TutorialsPoint. Simply Easy Learning.

IOTester.java

  1. import java.io.File;
  2. import java.io.IOException;
  3.  
  4. import org.apache.commons.io.FileUtils;
  5. import org.apache.commons.io.monitor.FileEntry;
  6.  
  7. public class IOTester {
  8. public static void main(String[] args) {
  9. try {
  10. usingFileEntry();
  11. } catch(IOException e) {
  12. System.out.println(e.getMessage());
  13. }
  14. }
  15.  
  16. public static void usingFileEntry() throws IOException {
  17. //get the file object
  18. File file = FileUtils.getFile("input.txt");
  19.  
  20. FileEntry fileEntry = new FileEntry(file);
  21.  
  22. System.out.println("Monitored File: " + fileEntry.getFile());
  23. System.out.println("File name: " + fileEntry.getName());
  24. System.out.println("Is Directory: " + fileEntry.isDirectory());
  25. }
  26. }

Output

It will print the following result.

  1. Monitored File: input.txt
  2. File name: input.txt
  3. Is Directory: false