本文整理了Java中java.io.FileFilter
类的一些代码示例,展示了FileFilter
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。FileFilter
类的具体详情如下:
包路径:java.io.FileFilter
类名称:FileFilter
[英]An interface for filtering File objects based on their names or other information.
[中]用于根据文件对象的名称或其他信息筛选文件对象的接口。
代码示例来源:origin: stanfordnlp/CoreNLP
/**
* Checks whether a file satisfies the selection filter.
*
* @param file The file
* @return true if the file is acceptable
*/
public boolean accept(File file) {
return ! f1.accept(file);
}
代码示例来源:origin: stackoverflow.com
File dir = new File(".");
FileFilter fileFilter = new WildcardFileFilter("sample*.java");
File[] files = dir.listFiles(fileFilter);
for (int i = 0; i < files.length; i++) {
System.out.println(files[i]);
}
代码示例来源:origin: stanfordnlp/CoreNLP
/**
* Checks whether a file satisfies the selection filter.
*
* @param file The file
* @return true if the file is acceptable
*/
public boolean accept(File file) {
return f1.accept(file) && f2.accept(file);
}
代码示例来源:origin: stackoverflow.com
import org.apache.commons.io.filefilter.WildcardFileFilter;
.........
.........
File dir = new File(fileDir);
FileFilter fileFilter = new WildcardFileFilter("*.txt");
File[] files = dir.listFiles(fileFilter);
代码示例来源:origin: redisson/redisson
public static boolean isFilePathAcceptable(File file, FileFilter fileFilter) {
do {
if (fileFilter != null && !fileFilter.accept(file)) {
return false;
}
file = file.getParentFile();
} while (file != null);
return true;
}
代码示例来源:origin: stackoverflow.com
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.comparator.LastModifiedFileComparator;
import org.apache.commons.io.filefilter.WildcardFileFilter;
...
/* Get the newest file for a specific extension */
public File getTheNewestFile(String filePath, String ext) {
File theNewestFile = null;
File dir = new File(filePath);
FileFilter fileFilter = new WildcardFileFilter("*." + ext);
File[] files = dir.listFiles(fileFilter);
if (files.length > 0) {
/** The newest file comes first **/
Arrays.sort(files, LastModifiedFileComparator.LASTMODIFIED_REVERSE);
theNewestFile = files[0];
}
return theNewestFile;
}
代码示例来源:origin: hawtio/hawtio
@Override
public boolean accept(File file) {
return filter1.accept(file) && filter2.accept(file);
}
};
代码示例来源:origin: stackoverflow.com
File dir = new File(".");
FileFilter fileFilter = new WildcardFileFilter("120*.txt");
File[] files = dir.listFiles(fileFilter);
for (int i = 0; i < files.length; i++) {
System.out.println(files[i].getName());
}
代码示例来源:origin: org.netbeans.api/org-openide-filesystems
@Override
public boolean accept(File pathname) {
return filter == null || filter.accept(pathname);
}
代码示例来源:origin: hawtio/hawtio
protected static boolean matches(FileFilter filter, File f) {
return filter == null || filter.accept(f);
}
代码示例来源:origin: oblac/jodd
/**
* Checks if file and its ancestors are acceptable by using {@link FileFilter#accept(File)}.
*
* @param file {@link File} to check.
* @param fileFilter {@link FileFilter} to use.
* @return if file and its ancestors are acceptable
*/
public static boolean isFilePathAcceptable(File file, final FileFilter fileFilter) {
do {
if (fileFilter != null && !fileFilter.accept(file)) {
return false;
}
file = file.getParentFile();
} while (file != null);
return true;
}
代码示例来源:origin: jenkinsci/jenkins
public void visit(File f, String relativePath) throws IOException {
if(f.isDirectory() || filter.accept(f))
visitor.visit(f,relativePath);
}
代码示例来源:origin: commons-io/commons-io
/**
* Checks the filter.
*
* @param file the file to check
* @return true if the filter matches
*/
@Override
public boolean accept(final File file) {
if (fileFilter != null) {
return fileFilter.accept(file);
} else {
return super.accept(file);
}
}
代码示例来源:origin: neo4j/neo4j
void addFile( File file )
{
if ( canBeManagedByPageCache( file ) || mappedIndexFilter.accept( file ) )
{
size += file.length();
}
}
代码示例来源:origin: org.apache.commons/commons-io
/**
* Checks the filter.
*
* @param file the file to check
* @return true if the filter matches
*/
public boolean accept(File file) {
if (fileFilter != null) {
return fileFilter.accept(file);
} else {
return super.accept(file);
}
}
代码示例来源:origin: robovm/robovm
/**
* Gets a list of the files in the directory represented by this file. This
* list is then filtered through a FileFilter and matching files are
* returned as an array of files. Returns {@code null} if this file is not a
* directory. If {@code filter} is {@code null} then all files match.
* <p>
* The entries {@code .} and {@code ..} representing the current and parent
* directories are not returned as part of the list.
*
* @param filter
* the filter to match names against, may be {@code null}.
* @return an array of files or {@code null}.
*/
public File[] listFiles(FileFilter filter) {
File[] files = listFiles();
if (filter == null || files == null) {
return files;
}
List<File> result = new ArrayList<File>(files.length);
for (File file : files) {
if (filter.accept(file)) {
result.add(file);
}
}
return result.toArray(new File[result.size()]);
}
代码示例来源:origin: zeroturnaround/zt-zip
private static void innerListFiles(File dir, Collection<File> accumulator, FileFilter filter) {
String[] filenames = dir.list();
if (filenames != null) {
for (int i = 0; i < filenames.length; i++) {
File file = new File(dir, filenames[i]);
if (file.isDirectory()) {
innerListFiles(file, accumulator, filter);
}
else {
if (filter != null && filter.accept(file)) {
accumulator.add(file);
}
}
}
}
}
}
代码示例来源:origin: libgdx/libgdx
public FileHandle[] list (String url, FileFilter filter) {
Array<FileHandle> files = new Array<FileHandle>();
for (String path : texts.keys()) {
if (isChild(path, url) && filter.accept(new File(path))) {
files.add(new GwtFileHandle(this, path, FileType.Internal));
}
}
FileHandle[] list = new FileHandle[files.size];
System.arraycopy(files.items, 0, list, 0, list.length);
return list;
}
代码示例来源:origin: libgdx/libgdx
public FileHandle[] list (String url, FileFilter filter) {
Array<FileHandle> files = new Array<FileHandle>();
for (String path : texts.keys()) {
if (isChild(path, url) && filter.accept(new File(path))) {
files.add(new GwtFileHandle(this, path, FileType.Internal));
}
}
FileHandle[] list = new FileHandle[files.size];
System.arraycopy(files.items, 0, list, 0, list.length);
return list;
}
代码示例来源:origin: looly/hutool
/**
* 递归遍历目录以及子目录中的所有文件<br>
* 如果提供file为文件,直接返回过滤结果
*
* @param file 当前遍历文件或目录
* @param fileFilter 文件过滤规则对象,选择要保留的文件,只对文件有效,不过滤目录
* @return 文件列表
*/
public static List<File> loopFiles(File file, FileFilter fileFilter) {
List<File> fileList = new ArrayList<File>();
if (null == file) {
return fileList;
} else if (false == file.exists()) {
return fileList;
}
if (file.isDirectory()) {
final File[] subFiles = file.listFiles();
if (ArrayUtil.isNotEmpty(subFiles)) {
for (File tmp : subFiles) {
fileList.addAll(loopFiles(tmp, fileFilter));
}
}
} else {
if (null == fileFilter || fileFilter.accept(file)) {
fileList.add(file);
}
}
return fileList;
}
内容来源于网络,如有侵权,请联系作者删除!