- 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 - IO案例
- Apache Commons IO - LineIterator
- Apache Commons IO - NameFileFilter
- Apache Commons IO - WildcardFileFilter
- Apache Commons IO - 后缀文件过滤器
- 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
- 最后修改文件比较器
- 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