Commons Io 简明教程
Apache Commons IO - FileEntry
FileEntry 提供文件或目录的状态。某一时刻的文件属性。
FileEntry provides the state of a file or directory. File attributes at a point in time.
Class Declaration
下列是 org.apache.commons.io.monitor.FileEntry 类的声明 −
Following is the declaration for org.apache.commons.io.monitor.FileEntry Class −
public class FileEntry
extends Object implements Serializable
Features of FileEntry
FileEntry 类对象在某一时刻提供以下文件属性。
FileEntry class object provides the 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 −
Welcome to TutorialsPoint. Simply Easy Learning.
IOTester.java
import java.io.File;
import java.io.IOException;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.monitor.FileEntry;
public class IOTester {
public static void main(String[] args) {
try {
usingFileEntry();
} catch(IOException e) {
System.out.println(e.getMessage());
}
}
public static void usingFileEntry() throws IOException {
//get the file object
File file = FileUtils.getFile("input.txt");
FileEntry fileEntry = new FileEntry(file);
System.out.println("Monitored File: " + fileEntry.getFile());
System.out.println("File name: " + fileEntry.getName());
System.out.println("Is Directory: " + fileEntry.isDirectory());
}
}