当前位置: 首页>>代码示例>>Java>>正文


Java FileUtils.listFiles方法代码示例

本文整理汇总了Java中org.apache.commons.io.FileUtils.listFiles方法的典型用法代码示例。如果您正苦于以下问题:Java FileUtils.listFiles方法的具体用法?Java FileUtils.listFiles怎么用?Java FileUtils.listFiles使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.commons.io.FileUtils的用法示例。


在下文中一共展示了FileUtils.listFiles方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: renameEmbededImages

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
/**
 * Give unique names to embedded images to ensure they aren't lost during merge
 * Update report file to reflect new image names
 *
 * @param reportFile
 */
public void renameEmbededImages(File reportFile) throws Throwable {
    File reportDirectory = reportFile.getParentFile();
    Collection<File> embeddedImages = FileUtils.listFiles(reportDirectory, new String[]{reportImageExtension}, true);

    String fileAsString = FileUtils.readFileToString(reportFile);

    for (File image : embeddedImages) {
        String curImageName = image.getName();
        String uniqueImageName = reportDirectory.getName() + "-" + UUID.randomUUID().toString() + "." + reportImageExtension;

        image.renameTo(new File(reportDirectory, uniqueImageName));
        fileAsString = fileAsString.replace(curImageName, uniqueImageName);
    }

    FileUtils.writeStringToFile(reportFile, fileAsString);
}
 
开发者ID:usman-h,项目名称:Habanero,代码行数:23,代码来源:JSONReportMerger.java

示例2: processResultsDirectory

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
public void processResultsDirectory(String dirName) {
	File root = new File(dirName);
	try {
		Collection<File> files = FileUtils.listFiles(root,
				new RegexFileFilter(jmeterJTLFileName),
				DirectoryFileFilter.DIRECTORY);

		for (Iterator<File> iterator = files.iterator(); iterator.hasNext();) {
			File file = (File) iterator.next();
			parse(file);
		}
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
开发者ID:WillemJiang,项目名称:acmeair,代码行数:16,代码来源:JmeterJTLParser.java

示例3: prepareApkFileList

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
protected static void prepareApkFileList(File folder, String prefixName, String awbName, ApkFiles apkFiles) {
    if (!folder.exists()) {
        return;
    }
    // Gets information about the main bundle
    Collection<File> files = FileUtils.listFiles(folder, new PureFileFilter(), TrueFileFilter.INSTANCE);
    for (File file : files) {
        if (file.isFile()) {
            String relativePath = prefixName + File.separator + PathUtil.toRelative(folder, file.getAbsolutePath());
            String md5 = MD5Util.getFileMD5(file);
            if (isImageFile(relativePath)) {
                if (null == apkFiles.apkFileList.getAwbs().get(awbName)) {
                    apkFiles.apkFileList.getAwbs().put(awbName, new HashMap<String, String>());
                }
                apkFiles.apkFileList.getAwbs().get(awbName).put(relativePath, md5);
            }
            if (null == apkFiles.finalApkFileList.getAwbs().get(awbName)) {
                apkFiles.finalApkFileList.getAwbs().put(awbName, new HashMap<String, String>());
            }
            apkFiles.finalApkFileList.getAwbs().get(awbName).put(relativePath, md5);
        }
    }

}
 
开发者ID:alibaba,项目名称:atlas,代码行数:25,代码来源:ApkFileListUtils.java

示例4: getExecutable

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
private String getExecutable() {
    File supposedExecutable = new File(executableDir + executableName);

    if(supposedExecutable.exists()) {
        return supposedExecutable.getAbsolutePath();
    } else {
        Collection<File> theExecutable = FileUtils.listFiles(new File(executableDir), new WildcardFileFilter(executableName), TrueFileFilter.INSTANCE);

        if(theExecutable != null || theExecutable.size() > 1 || theExecutable.isEmpty()) {
            File newestExecutable = theExecutable.stream().reduce(new File(""),
                    (aFile, newestFile) -> {
                        if(aFile.lastModified() > newestFile.lastModified()) {
                            return aFile;
                        }

                        return newestFile;
                    });

            return newestExecutable.getAbsolutePath();
        } else if(theExecutable.size() == 1) {
            return ((File)CollectionUtils.get(theExecutable, 0)).getAbsolutePath();
        } else {
            throw new RuntimeException("Could not determine executable path");
        }
    }
}
 
开发者ID:corydissinger,项目名称:mtgo-best-bot,代码行数:27,代码来源:ProcessManager.java

示例5: getResourcesWithExtension

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
public ArrayList<String> getResourcesWithExtension(String ext, String containerName) {
	ArrayList<String> ret = new ArrayList<String>();
	if (containerName != null) {
		String[] names = StringUtils.split(containerName, "/");
		IWorkspaceRoot wsRoot = ResourcesPlugin.getWorkspace().getRoot();
		IResource resource = wsRoot.findMember(new Path("/" + names[0]));
		IPath loc = resource.getLocation();
		File prjLoc = new File(loc.toString());
		Collection<File> res = FileUtils.listFiles(prjLoc, FileFilterUtils.suffixFileFilter(ext, IOCase.INSENSITIVE), TrueFileFilter.INSTANCE);
		for (File file : res)
			ret.add(file.getAbsolutePath());
	}
	return ret;
}
 
开发者ID:dstl,项目名称:Open_Source_ECOA_Toolset_AS5,代码行数:15,代码来源:PluginUtil.java

示例6: testJavaLanguageFundamentals

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
public void testJavaLanguageFundamentals() throws IOException, InterruptedException {
    File parent = new File("C:\\github\\javaide2\\app\\src\\main\\assets\\sample\\JavaLanguageFundamentals");
    Collection<File> files = FileUtils.listFiles(parent, new String[]{"java"}, true);
    for (File file : files) {
        System.out.println(file);

        Process exec = Runtime.getRuntime().exec("javac " + file.getPath());
        exec.waitFor();
        InputStream inputStream = exec.getErrorStream();
        printStream(inputStream);
    }
    files = FileUtils.listFiles(parent, new String[]{"class"}, true);
    for (File f : files) {
        f.delete();
    }
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:17,代码来源:SampleDataTest.java

示例7: generate

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
@Override
public void generate(Api api, File outputPath) throws IOException {
    if (outputPath.exists()) {
        Collection<File> files = FileUtils.listFiles(
                outputPath,
                TrueFileFilter.INSTANCE,
                TrueFileFilter.INSTANCE
        );
        for (File file : files) {
            if (file.isFile()) {
                Files.deleteIfExists(file.toPath());
            }
        }
    } else {
        Files.createDirectories(outputPath.toPath());
    }

    TypesGenerator generator = new TypesGenerator();
    generator.generate(api.getTypes(), new File(outputPath, "types") );

}
 
开发者ID:vrapio,项目名称:rest-modeling-framework,代码行数:22,代码来源:MdGenerator.java

示例8: listClassName

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
public static ArrayList<String> listClassName(File src) {
    if (!src.exists()) return new ArrayList<>();

    String[] exts = new String[]{"java"};
    Collection<File> files = FileUtils.listFiles(src, exts, true);

    ArrayList<String> classes = new ArrayList<>();
    String srcPath = src.getPath();
    for (File file : files) {
        String javaPath = file.getPath();
        javaPath = javaPath.substring(srcPath.length(), javaPath.length() - 5); //.java
        javaPath = javaPath.replace(File.separator, ".");
        classes.add(javaPath);
    }
    return classes;
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:17,代码来源:FileTest.java

示例9: copyLocalNativeLibraries

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
/**
 * @param localNativeLibrariesDirectory
 * @param destinationDirectory
 * @param supportAbis                   Type of architecture supported
 * @param removeSoFiles
 */
public static void copyLocalNativeLibraries(final File localNativeLibrariesDirectory,
                                            final File destinationDirectory, Set<String> supportAbis,
                                            Set<String> removeSoFiles) {
    sLogger.info("Copying existing native libraries from " + localNativeLibrariesDirectory + " to "
                     + destinationDirectory);
    try {
        IOFileFilter filter = new NativeSoFilter(supportAbis, removeSoFiles);
        // First, determine whether there is a file of the same name, if there is a discrepancy
        Collection<File> files = FileUtils.listFiles(localNativeLibrariesDirectory, filter, TrueFileFilter.TRUE);
        List<String> dumpFiles = new ArrayList<String>();
        for (File file : files) {
            String relativePath = getRelativePath(localNativeLibrariesDirectory, file);
            File destFile = new File(destinationDirectory, relativePath);
            if (destFile.exists()) {
                String orgFileMd5 = MD5Util.getFileMD5(file);
                String destFileMd5 = MD5Util.getFileMD5(destFile);
                if (!orgFileMd5.equals(destFileMd5)) {
                    dumpFiles.add(file.getAbsolutePath() + " to " + destFile.getAbsolutePath());
                }
            }
        }
        if (dumpFiles.size() > 0) {
            throw new RuntimeException("Copy native so error,duplicate file exist!:\n"
                                           + StringUtils.join(dumpFiles, "\n"));
        }
        FileUtils.copyDirectory(localNativeLibrariesDirectory, destinationDirectory, filter);
    } catch (IOException e) {
        throw new RuntimeException("Could not copy native dependency.", e);
    }
}
 
开发者ID:alibaba,项目名称:atlas,代码行数:37,代码来源:NativeSoUtils.java

示例10: test

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
@Test
public void test(){
    Collection<File> files = FileUtils.listFiles(new File(PATH_NAME), new String[]{"jar"}, false);
    StringBuilder cmd = new StringBuilder("storm --jars \"");
    files.forEach(file -> {
        cmd.append("libs/").append(file.getName()).append(",");
    });
    cmd.deleteCharAt(cmd.length()-1);
    cmd.append("\" jar ").append(FINAL_NAME)
            .append(" com.maxplus1.DemoApplication ");
    System.out.println("====================================");
    System.out.println(cmd.toString());
    System.out.println("====================================");
}
 
开发者ID:Paleozoic,项目名称:storm_spring_boot_demo,代码行数:15,代码来源:buildStormCmd.java

示例11: doInBackground

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
@Override
public Void doInBackground() throws Exception {
  if (SwingUtilities.isEventDispatchThread()) {
    throw new Exception("Worker should not run on the EDT thread!");
  }

  LOGGER.info("------------------- Searching in {} -------------------", searchDirectory.getAbsolutePath());
  Integer nbAnnotated = 0;
  for (File fileEntry : FileUtils.listFiles(searchDirectory, searchExtensions, true)) {
    try {
      if (processFile(fileEntry)) {
        nbAnnotated++;
      }
    } catch (Exception exc) {
      LOGGER.error("Error while trying to annotate {}. See log for details. Skip file.", fileEntry.getName());
      LOGGER.debug("Got exception", exc);
    }

    if (isCancelled()) {
      LOGGER.debug("WorkerSubAnnotator was cancelled.");
      return null;
    }
  }

  if (nbAnnotated > 0) {
    LOGGER.info("{} subtitle files were annotated.", nbAnnotated);
  } else {
    LOGGER.info("No subtitle found in this directory.");
  }
  return null;
}
 
开发者ID:juliango202,项目名称:jijimaku,代码行数:32,代码来源:WorkerAnnotate.java

示例12: test_pack

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
public void test_pack() {
    ArchiveBean archiveBean = new ArchiveBean();
    try {
        archiveBean.afterPropertiesSet();
        archiveBean.setUseLocalFileMutliThread(false);
    } catch (Exception e1) {
        want.fail();
    }

    File file = new File("/tmp/otter/test");
    Collection<File> allFiles = FileUtils.listFiles(file, new String[] { "jpg" }, true);

    List<FileData> fileDatas = new ArrayList<FileData>();
    for (File files : allFiles) {
        FileData data = new FileData();
        // data.setPath("wsproduct_repository/product_sku/76/84/32/84/768432847_10.summ.jpg");
        data.setPath(StringUtils.substringAfter(files.getAbsolutePath(), "/tmp/otter/test"));
        fileDatas.add(data);
    }

    File archiveFile = new File("/tmp/otter/test.gzip");
    if (archiveFile.exists()) {
        archiveFile.delete();
    }

    boolean result = archiveBean.pack(archiveFile, fileDatas, new ArchiveRetriverCallback<FileData>() {

        public InputStream retrive(FileData source) {
            return new LazyFileInputStream(new File("/tmp/otter/test", source.getPath()));
        }
    });

    if (!result) {
        want.fail();
    }

}
 
开发者ID:luoyaogui,项目名称:otter-G,代码行数:38,代码来源:ArchiveBeanIntegration.java

示例13: listFiles

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
public void listFiles(String rootDir){
	File dir = new File(rootDir);

	List<File> files = (List<File>) FileUtils.listFiles(dir, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE);
	for (File file : files) {
		System.out.println("file: " + file.getAbsolutePath());
	}
}
 
开发者ID:PacktPublishing,项目名称:Java-Data-Science-Cookbook,代码行数:9,代码来源:FileListing.java

示例14: removeOldInstall

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
private void removeOldInstall() throws IOException {
  Collection<File> filesToDelete = FileUtils.listFiles(installDir, new String[]{"jar"}, false);
  List<File> directories = Arrays.stream(INSTALLER_DIRS)
      .map(s -> new File(installDir, s))
      .collect(Collectors.toList());

  filesToDelete.addAll(directories);

  EStream.from(filesToDelete)
      .filter(File::exists)
      .forEach(FileUtils::forceDelete);
}
 
开发者ID:Juraji,项目名称:Biliomi,代码行数:13,代码来源:FindUpdatesSetupTask.java

示例15: search4FileInDir

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
/**
* Search for extensions in a directory (or list all files in directory)
* @param path
* @param extensions filter by extension types
* @return
*/
public List<File> search4FileInDir(String path, String[] extensions){
	File dir = new File(path);
	List<File> files;
	if (extensions != null){
		files = (List<File>)FileUtils.listFiles(dir, extensions, true);
		
	}
	else {
		files = (List<File>)FileUtils.listFiles(dir, null, true);
	}
	return files;
	
}
 
开发者ID:ernw,项目名称:AndroTickler,代码行数:20,代码来源:SearchUtil.java


注:本文中的org.apache.commons.io.FileUtils.listFiles方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。