- Apache Commons IO 教程
- Apache Commons IO - 主頁
- Apache Commons IO - 概述
- Apache Commons IO - 環境設定
- Apache Commons IO - IOUtils
- Apache Commons IO - FileUtils
- Apache Commons IO - FilenameUtils
- Apache Commons IO - FileSystemUtils
- Apache Commons IO - IOCase
- Apache Commons IO - LineIterator
- Apache Commons IO - NameFileFilter
- Apache Commons IO - WildcardFileFilter
- Apache Commons IO - SuffixFileFilter
- Apache Commons IO - PrefixFileFilter
- Apache Commons IO - OrFileFilter
- Apache Commons IO - AndFileFilter
- Apache Commons IO - 檔案條目
- Apache Commons IO - FileAlterationObserver
- Apache Commons IO - FileAlterationMonitor
- Apache Commons IO - NameFileComparator
- Apache Commons IO - SizeFileComparator
- LastModifiedFileComparator
- Apache Commons IO - TeeInputStream
- Apache Commons IO - TeeOutputStream
- Apache Commons IO - 有用資源
- Apache Commons IO - 快速指南
- Apache Commons IO - 有用資源
- Apache Commons IO - 討論
Apache Commons IO - 檔案條目
檔案條目提供檔案或目錄的狀態。某個時間點上的檔案屬性。
類宣告
以下是 org.apache.commons.io.monitor.FileEntry 類的宣告 -
public class FileEntry extends Object implements Serializable
檔案條目的特性
在某個時間點上,FileEntry 類物件提供以下檔案屬性。
getName() - 檔名。
exists() - 檢查檔案是否存在。
isDirectory() - 檢查檔案是否為目錄。
lastModified() - 給出最後修改日期時間。
listFiles() - 給出目錄的內容。
FileEntry 類的示例
這裡是我們需要解析的輸入檔案 -
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());
}
}
輸出結果
它將列印以下結果。
Monitored File: input.txt File name: input.txt Is Directory: false
廣告