當前位置: 首頁>>代碼示例>>Java>>正文


Java FileFilter.accept方法代碼示例

本文整理匯總了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;
}
 
開發者ID:senierr,項目名稱:ModuleFrame,代碼行數:25,代碼來源:FileUtil.java

示例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;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:29,代碼來源:FileUtils.java

示例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;
}
 
開發者ID:fabric8-updatebot,項目名稱:updatebot,代碼行數:20,代碼來源:FileHelper.java

示例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()]);
}
 
開發者ID:miLLlulei,項目名稱:Accessibility,代碼行數:27,代碼來源:FileUtils.java

示例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;
}
 
開發者ID:MobClub,項目名稱:BBSSDK-for-Android,代碼行數:28,代碼來源:FileUtils.java

示例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;
}
 
開發者ID:clickha,項目名稱:nifi-tools,代碼行數:26,代碼來源:ListFile.java

示例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()]);

}
 
開發者ID:feifadaima,項目名稱:https-github.com-hyb1996-NoRootScriptDroid,代碼行數:14,代碼來源:ScriptFile.java

示例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;
}
 
開發者ID:dream-lab,項目名稱:echo,代碼行數:28,代碼來源:GetFileFromAttribute.java

示例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;
}
 
開發者ID:qq1198,項目名稱:mtoolbox,代碼行數:11,代碼來源:CompositeFilter.java

示例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;
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:55,代碼來源:DirectoryScannerConfig.java

示例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);
        }
    }
}
 
開發者ID:dryganets,項目名稱:vogar,代碼行數:14,代碼來源:RetrieveFilesTask.java

示例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;
}
 
開發者ID:apache,項目名稱:directory-ldap-api,代碼行數:38,代碼來源:OsgiUtils.java

示例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;
}
 
開發者ID:Axway,項目名稱:ats-framework,代碼行數:44,代碼來源:LocalFileSystemOperations.java

示例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;
}
 
開發者ID:hortonworks,項目名稱:nifi-android-s2s,代碼行數:10,代碼來源:AndFileFilter.java

示例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;
}
 
開發者ID:hortonworks,項目名稱:nifi-android-s2s,代碼行數:10,代碼來源:OrFileFilter.java


注:本文中的java.io.FileFilter.accept方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。