- 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 - FileEntry
- 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 - NameFileComparator
NameFileComparator 比較二個檔案的名稱。它可用於根據檔名(區分大小寫、不區分大小寫或依賴於系統大小寫)對檔案列表或陣列進行排序。
類宣告
以下是
org.apache.commons.io.comparator.NameFileComparator 類的宣告:
public class NameFileComparator extends Object implements Serializable
NameFileComparator 類示例
以下是我們需要解析的輸入檔案:
Welcome to TutorialsPoint. Simply Easy Learning.
IOTester.java
import java.io.File;
import java.io.FileFilter;
import java.io.IOException;
import org.apache.commons.io.IOCase;
import org.apache.commons.io.comparator.NameFileComparator;
import org.apache.commons.io.filefilter.FileFileFilter;
public class IOTester {
public static void main(String[] args) {
try {
usingNameFileComparator();
} catch(IOException e) {
System.out.println(e.getMessage());
}
}
public static void usingNameFileComparator() throws IOException {
//get the current directory
File currentDirectory = new File(".");
NameFileComparator comparator = new
NameFileComparator(IOCase.INSENSITIVE);
File[] sortedFiles = comparator.sort(currentDirectory.listFiles((FileFilter)FileFileFilter.FILE));
System.out.println("Sorted By Name: ");
for(File file:sortedFiles) {
System.out.println(file.getName());
}
}
}
輸出
它將列印以下結果。
Sorted By Name: .classpath .project input.txt
廣告