- 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 - OrFileFilter
OrFileFilter 提供跨檔案過濾器列表的條件 OR 邏輯。如果列表中的任一過濾器返回 true,它將返回 true。否則,它將返回 false。
類宣告
下面是 org.apache.commons.io.filefilter.OrFileFilter 類的宣告 -
public class OrFileFilter extends AbstractFileFilter implements ConditionalFileFilter, Serializable
OrFileFilter 類的示例
以下是我們需要解析的輸入檔案 -
Welcome to TutorialsPoint. Simply Easy Learning.
讓我們列印當前目錄中的所有檔案和目錄,然後過濾一個以 . 開頭或以 t 結尾的檔案。
IOTester.java
import java.io.File;
import java.io.IOException;
import org.apache.commons.io.filefilter.OrFileFilter;
import org.apache.commons.io.filefilter.PrefixFileFilter;
import org.apache.commons.io.filefilter.WildcardFileFilter;
public class IOTester {
public static void main(String[] args) {
try {
usingOrFileFilter();
} catch(IOException e) {
System.out.println(e.getMessage());
}
}
public static void usingOrFileFilter() 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 . or ends with t\n");
String[] filesNames = currentDirectory.list( new OrFileFilter(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 .classpath .project .settings input.txt
廣告