本文整理汇总了Java中java.io.FileFilter.accept方法的典型用法代码示例。如果您正苦于以下问题:Java FileFilter.accept方法的具体用法?Java FileFilter.accept怎么用?Java FileFilter.accept使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.io.FileFilter
的用法示例。
在下文中一共展示了FileFilter.accept方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: deleteFilesInDirWithFilter
import java.io.FileFilter; //导入方法依赖的package包/类
/**
* 删除目录下所有过滤的文件
*
* @param dir 目录
* @param filter 过滤器
* @return {@code true}: 删除成功<br>{@code false}: 删除失败
*/
public static boolean deleteFilesInDirWithFilter(final File dir, final FileFilter filter) {
if (!isFileExists(dir)) return true;
if (!dir.isDirectory()) return false;
File[] files = dir.listFiles();
if (files != null && files.length != 0) {
for (File file : files) {
if (filter.accept(file)) {
if (file.isFile()) {
if (!file.delete()) return false;
} else if (file.isDirectory()) {
if (!deleteDir(file)) return false;
}
}
}
}
return true;
}
示例2: deleteFilesInDirWithFilter
import java.io.FileFilter; //导入方法依赖的package包/类
/**
* 删除目录下所有过滤的文件
*
* @param dir 目录
* @param filter 过滤器
* @return {@code true}: 删除成功<br>{@code false}: 删除失败
*/
public static boolean deleteFilesInDirWithFilter(final File dir, final FileFilter filter) {
if (dir == null) return false;
// 目录不存在返回true
if (!dir.exists()) return true;
// 不是目录返回false
if (!dir.isDirectory()) return false;
// 现在文件存在且是文件夹
File[] files = dir.listFiles();
if (files != null && files.length != 0) {
for (File file : files) {
if (filter.accept(file)) {
if (file.isFile()) {
if (!file.delete()) return false;
} else if (file.isDirectory()) {
if (!deleteDir(file)) return false;
}
}
}
}
return true;
}
示例3: hasFile
import java.io.FileFilter; //导入方法依赖的package包/类
/**
* Returns true if a file matching the filter can be found in the given directory
*/
public static boolean hasFile(File dir, FileFilter filter) {
if (filter.accept(dir)) {
return true;
}
if (dir.isDirectory()) {
File[] files = dir.listFiles();
if (files != null) {
for (File file : files) {
if (hasFile(file, filter)) {
return true;
}
}
}
}
return false;
}
示例4: listFiles
import java.io.FileFilter; //导入方法依赖的package包/类
/**
* 实现listFiles功能,遍历过程中进行锁判斿
*/
private File[] listFiles(File f, FileFilter filter) {
if (f == null) {
return null;
}
File[] files = f.listFiles();
if (filter == null || files == null) {
return files;
}
List<File> result = new ArrayList<File>(files.length);
for (File file : files) {
if (mLock.isExit()) {
break;
} else {
mLock.callWait();
}
if (filter.accept(file)) {
result.add(file);
}
}
return result.toArray(new File[result.size()]);
}
示例5: listFilesInDirWithFilter
import java.io.FileFilter; //导入方法依赖的package包/类
/**
* 获取目录下所有过滤的文件
*
* @param dir 目录
* @param filter 过滤器
* @param isRecursive 是否递归进子目录
* @return 文件链表
*/
public static List<File> listFilesInDirWithFilter(final File dir, final FileFilter filter, final boolean isRecursive) {
if (!isDir(dir)) {
return null;
}
List<File> list = new ArrayList<File>();
File[] files = dir.listFiles();
if (files != null && files.length != 0) {
for (File file : files) {
if (filter.accept(file)) {
list.add(file);
}
if (isRecursive && file.isDirectory()) {
//noinspection ConstantConditions
list.addAll(listFilesInDirWithFilter(file, filter, true));
}
}
}
return list;
}
示例6: scanDirectory
import java.io.FileFilter; //导入方法依赖的package包/类
private List<FileInfo> scanDirectory(final File path, final FileFilter filter, final Boolean recurse,
final Long minTimestamp) throws IOException {
final List<FileInfo> listing = new ArrayList<>();
File[] files = path.listFiles();
if (files != null) {
for (File file : files) {
if (file.isDirectory()) {
if (recurse) {
listing.addAll(scanDirectory(file, filter, true, minTimestamp));
}
} else {
if ((minTimestamp == null || file.lastModified() >= minTimestamp) && filter.accept(file)) {
listing.add(new FileInfo.Builder()
.directory(file.isDirectory())
.filename(file.getName())
.fullPathFileName(file.getAbsolutePath())
.lastModifiedTime(file.lastModified())
.build());
}
}
}
}
return listing;
}
示例7: listFiles
import java.io.FileFilter; //导入方法依赖的package包/类
@Override
public ScriptFile[] listFiles(FileFilter filter) {
String ss[] = list();
if (ss == null) return null;
ArrayList<ScriptFile> files = new ArrayList<>();
for (String s : ss) {
ScriptFile f = new ScriptFile(this, s);
if ((filter == null) || filter.accept(f))
files.add(f);
}
return files.toArray(new ScriptFile[files.size()]);
}
示例8: performListing
import java.io.FileFilter; //导入方法依赖的package包/类
private Set<File> performListing(final File directory, final FileFilter filter, final boolean recurseSubdirectories) {
Path p = directory.toPath();
if (!Files.isWritable(p) || !Files.isReadable(p)) {
throw new IllegalStateException("Directory '" + directory + "' does not have sufficient permissions (i.e., not writable and readable)");
}
final Set<File> queue = new HashSet<File>();
if (!directory.exists()) {
return queue;
}
final File[] children = directory.listFiles();
if (children == null) {
return queue;
}
for (final File child : children) {
if (child.isDirectory()) {
if (recurseSubdirectories) {
queue.addAll(performListing(child, filter, recurseSubdirectories));
}
} else if (filter.accept(child)) {
queue.add(child);
}
}
return queue;
}
示例9: accept
import java.io.FileFilter; //导入方法依赖的package包/类
@Override
public boolean accept(File f) {
for (FileFilter filter : mFilters) {
if (!filter.accept(f)) {
return false;
}
}
return true;
}
示例10: buildFileFilter
import java.io.FileFilter; //导入方法依赖的package包/类
/**
* Builds a {@code FileFilter} from the {@link #getIncludeFiles
* includeFiles} and {@link #getExcludeFiles excludeFiles} lists.
* A file will be accepted if it is selected by at least one of
* the filters in {@link #getIncludeFiles includeFiles}, and is
* not excluded by any of the filters in {@link
* #getExcludeFiles excludeFiles}. If there's no filter in
* {@link #getIncludeFiles includeFiles}, then a file is accepted
* simply if it is not excluded by any of the filters in {@link
* #getExcludeFiles excludeFiles}.
*
* @return A new {@code FileFilter} created from the current snapshot
* of the {@link #getIncludeFiles
* includeFiles} and {@link #getExcludeFiles excludeFiles} lists.
* Later modification of these lists will not affect the
* returned {@code FileFilter}.
**/
public FileFilter buildFileFilter() {
final FileFilter[] ins = getIncludeFiles();
final FileFilter[] outs = getExcludeFiles();
final FileFilter filter = new FileFilter() {
public boolean accept(File f) {
boolean result = false;
// If no include filter, all files are included.
if (ins != null) {
for (FileFilter in: ins) {
// if one filter accepts it, file is included
if (!in.accept(f)) continue;
// file is accepted, include it
result=true;
break;
}
} else result= true;
if (result == false) return false;
// The file is in the include list. Let's see if it's not
// in the exclude list...
//
if (outs != null) {
for (FileFilter out: outs) {
// if one filter accepts it, file is excluded
if (!out.accept(f)) continue;
// file is accepted, exclude it.
result=false;
break;
}
}
return result;
}
};
return filter;
}
示例11: retrieveFiles
import java.io.FileFilter; //导入方法依赖的package包/类
/**
* Scans {@code dir} for files to grab.
*/
private void retrieveFiles(File destination, File source, FileFilter filenameFilter)
throws FileNotFoundException {
for (File file : run.target.ls(source)) {
if (filenameFilter.accept(file)) {
run.log.info("Moving " + file + " to " + destination);
run.mkdir.mkdirs(destination);
run.target.pull(file, destination);
}
}
}
示例12: getClasspathCandidates
import java.io.FileFilter; //导入方法依赖的package包/类
/**
* Get the files that fits a given filter
*
* @param filter The filter in use
* @return The set of Files that match the filter
*/
public static Set<File> getClasspathCandidates( FileFilter filter )
{
Set<File> candidates = new HashSet<>();
String separator = System.getProperty( "path.separator" );
String[] cpElements = System.getProperty( "java.class.path" ).split( separator );
for ( String element : cpElements )
{
File candidate = new File( element );
if ( candidate.isFile() )
{
if ( filter != null && filter.accept( candidate ) )
{
candidates.add( candidate );
LOG.info( "Accepted candidate with filter: {}", candidate.toString() );
}
else if ( filter == null && candidate.getName().endsWith( ".jar" ) )
{
candidates.add( candidate );
LOG.info( "Accepted candidate without filter: {}", candidate.toString() );
}
else
{
LOG.info( "Rejecting candidate: {}", candidate.toString() );
}
}
}
return candidates;
}
示例13: getMatchingFiles
import java.io.FileFilter; //导入方法依赖的package包/类
/**
* Get the files in a folder which match the given {@link FileFilter}
*
* @param startLocation the start location in which to look
* @param searchFilter the search filter to apply
* @param recursiveSearch
* @return list of matching files
*/
private List<String> getMatchingFiles(
File startLocation,
FileFilter searchFilter,
boolean recursiveSearch ) {
List<String> matchingFiles = new ArrayList<String>();
File[] files = startLocation.listFiles();
// listFiles() can return 'null' even when we have no rights to read in the 'startLocaltion' directory
if (files != null) {
for (File child : files) {
if (searchFilter.accept(child)) {
try {
String path = child.getCanonicalPath();
if (child.isDirectory()) {
// when the path points to a directory, we add file separator character at the end
matchingFiles.add(IoUtils.normalizeDirPath(path));
} else {
matchingFiles.add(path);
}
} catch (IOException ioe) {
throw new FileSystemOperationException("Could not get the canonical path of file: "
+ child.getAbsolutePath(), ioe);
}
}
//if recursion is allowed
if (recursiveSearch && child.isDirectory()) {
matchingFiles.addAll(getMatchingFiles(child, searchFilter, recursiveSearch));
}
}
}
return matchingFiles;
}
示例14: accept
import java.io.FileFilter; //导入方法依赖的package包/类
@Override
public boolean accept(File pathname) {
for (FileFilter delegate : delegates) {
if (!delegate.accept(pathname)) {
return false;
}
}
return true;
}
示例15: accept
import java.io.FileFilter; //导入方法依赖的package包/类
@Override
public boolean accept(File pathname) {
for (FileFilter delegate : delegates) {
if (delegate.accept(pathname)) {
return true;
}
}
return false;
}