- 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 - AndFileFilter
AndFileFilter 提供跨文件过滤器列表的条件和逻辑。如果列表中的所有过滤器都返回 true,则它返回 true。否则,返回 false。
类别声明
以下是org.apache.commons.io.filefilter.AndFileFilter类的声明-
public class AndFileFilter extends AbstractFileFilter implements ConditionalFileFilter, Serializable
AndFileFilter 类示例
这是我们需要解析的输入文件 -
Welcome to TutorialsPoint. Simply Easy Learning.
让我们打印当前目录中的所有文件和目录,然后过滤名称以 . 并以 t 结尾。
IOTester.java
import java.io.File;
import java.io.IOException;
import org.apache.commons.io.filefilter.AndFileFilter;
import org.apache.commons.io.filefilter.PrefixFileFilter;
import org.apache.commons.io.filefilter.WildcardFileFilter;
public class IOTester {
public static void main(String[] args) {
try {
usingAndFileFilter();
} catch(IOException e) {
System.out.println(e.getMessage());
}
}
public static void usingAndFileFilter() throws IOException {
//get the current directory
File currentDirectory = new File(".");
//get names of all files and directory in current directory
String[] files = currentDirectory.list();
System.out.println("All files and Folders.\n");
for( int i = 0; i < files.length; i++ ) {
System.out.println(files[i]);
}
System.out.println("\nFile starting with . and ends with t\n");
String[] filesNames = currentDirectory.list( new AndFileFilter(
new PrefixFileFilter("."), new WildcardFileFilter("*t")));
for( int i = 0; i < filesNames.length; i++ ) {
System.out.println(filesNames[i]);
}
}
}
输出
它将打印以下结果。
All files and Folders. .classpath .project .settings bin input.txt src File starting with . or ends with t .project