org.apache.commons.io.FileUtils.deleteDirectory()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(7.5k)|赞(0)|评价(0)|浏览(405)

本文整理了Java中org.apache.commons.io.FileUtils.deleteDirectory()方法的一些代码示例,展示了FileUtils.deleteDirectory()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。FileUtils.deleteDirectory()方法的具体详情如下:
包路径:org.apache.commons.io.FileUtils
类名称:FileUtils
方法名:deleteDirectory

FileUtils.deleteDirectory介绍

[英]Deletes a directory recursively.
[中]递归删除目录。

代码示例

代码示例来源:origin: gocd/gocd

public static void deleteDirectoryNoisily(File defaultDirectory) {
  if (!defaultDirectory.exists()) {
    return;
  }
  try {
    FileUtils.deleteDirectory(defaultDirectory);
  } catch (IOException e) {
    throw new RuntimeException("Failed to delete directory: " + defaultDirectory.getAbsolutePath(), e);
  }
}

代码示例来源:origin: twosigma/beakerx

private void deletePomFolder(File finalPom) {
 if (finalPom != null) {
  File parentFile = new File(finalPom.getParent());
  try {
   FileUtils.deleteDirectory(parentFile);
  } catch (IOException e) {
  }
 }
}

代码示例来源:origin: geoserver/geoserver

/**
 * Backs up a directory <tt>dir</tt> by creating a .bak next to it.
 *
 * @param dir The directory to back up.
 */
public static void backupDirectory(File dir) throws IOException {
  File bak = new File(dir.getCanonicalPath() + ".bak");
  if (bak.exists()) {
    FileUtils.deleteDirectory(bak);
  }
  dir.renameTo(bak);
}

代码示例来源:origin: apache/geode

/**
 * Cleans up the installation by deleting the extracted module and downloaded installation folders
 */
public void clearPreviousInstall(String installDir) throws IOException {
 File installFolder = new File(installDir);
 // Remove installs from previous runs in the same folder
 if (installFolder.exists()) {
  logger.info("Deleting previous install folder " + installFolder.getAbsolutePath());
  FileUtils.deleteDirectory(installFolder);
 }
}

代码示例来源:origin: apache/incubator-druid

TmpFileSegmentWriteOutMedium(File outDir) throws IOException
{
 File tmpOutputFilesDir = new File(outDir, "tmpOutputFiles");
 FileUtils.forceMkdir(tmpOutputFilesDir);
 closer.register(() -> FileUtils.deleteDirectory(tmpOutputFilesDir));
 this.dir = tmpOutputFilesDir;
}

代码示例来源:origin: eirslett/frontend-maven-plugin

private void deleteTempDirectory(File tmpDirectory) throws IOException {
  if (tmpDirectory != null && tmpDirectory.exists()) {
    this.logger.debug("Deleting temporary directory {}", tmpDirectory);
    FileUtils.deleteDirectory(tmpDirectory);
  }
}

代码示例来源:origin: square/spoon

private void cleanScreenshotsDirectory(DeviceResult.Builder result) throws IOException {
 File screenshotDir = new File(work, DEVICE_SCREENSHOT_DIR);
 if (screenshotDir.exists()) {
  imageDir.mkdirs();
  handleImages(result, screenshotDir);
  FileUtils.deleteDirectory(screenshotDir);
 }
}

代码示例来源:origin: apache/kylin

public void cleanStorage() {
    logger.info("clean cache storage for path:" + cachePath);
    try {
      FileUtils.deleteDirectory(new File(cachePath));
    } catch (IOException e) {
      logger.error("file delete fail:" + cachePath, e);
    }
  }
}

代码示例来源:origin: azkaban/azkaban

/**
 * Clean up the directory.
 *
 * @param dir the directory to be deleted
 */
public static void cleanUpDir(final File dir) {
 try {
  if (dir != null && dir.exists()) {
   FileUtils.deleteDirectory(dir);
  }
 } catch (final IOException e) {
  logger.error("Failed to delete the directory", e);
  dir.deleteOnExit();
 }
}

代码示例来源:origin: square/spoon

private void cleanFilesDirectory(DeviceResult.Builder result) throws IOException {
 File testFilesDir = new File(work, DEVICE_FILE_DIR);
 if (testFilesDir.exists()) {
  fileDir.mkdirs();
  handleFiles(result, testFilesDir);
  FileUtils.deleteDirectory(testFilesDir);
 }
}

代码示例来源:origin: apache/geode

public static File createTestRootDiskStore(String testName) throws IOException {
 File diskDir = new File(testName).getAbsoluteFile();
 FileUtils.deleteDirectory(diskDir);
 diskDir.mkdir();
 diskDir.deleteOnExit();
 return diskDir;
}

代码示例来源:origin: commons-io/commons-io

/**
 * Deletes a file. If file is a directory, delete it and all sub-directories.
 * <p>
 * The difference between File.delete() and this method are:
 * <ul>
 * <li>A directory to be deleted does not have to be empty.</li>
 * <li>You get exceptions when a file or directory cannot be deleted.
 * (java.io.File methods returns a boolean)</li>
 * </ul>
 *
 * @param file file or directory to delete, must not be {@code null}
 * @throws NullPointerException  if the directory is {@code null}
 * @throws FileNotFoundException if the file was not found
 * @throws IOException           in case deletion is unsuccessful
 */
public static void forceDelete(final File file) throws IOException {
  if (file.isDirectory()) {
    deleteDirectory(file);
  } else {
    final boolean filePresent = file.exists();
    if (!file.delete()) {
      if (!filePresent) {
        throw new FileNotFoundException("File does not exist: " + file);
      }
      final String message =
          "Unable to delete file: " + file;
      throw new IOException(message);
    }
  }
}

代码示例来源:origin: apache/incubator-gobblin

private void cleanUpClusterWorkDirectory(String clusterId) throws IOException {
 final File appWorkDir = new File(GobblinClusterUtils.getAppWorkDirPath(this.clusterName, clusterId));
 if (appWorkDir.exists() && appWorkDir.isDirectory()) {
  LOGGER.info("Deleting application working directory " + appWorkDir);
  FileUtils.deleteDirectory(appWorkDir);
 }
}

代码示例来源:origin: JpressProjects/jpress

public void uninstall(){
    try {
      FileUtils.deleteDirectory(new File(getAbsolutePath()));
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
}

代码示例来源:origin: SonarSource/sonarqube

private static void cleanupOutdatedEsData(EsInstallation esInstallation) {
 esInstallation.getOutdatedSearchDirectories().forEach(outdatedDir -> {
  if (outdatedDir.exists()) {
   LOG.info("Deleting outdated search index data directory {}", outdatedDir.getAbsolutePath());
   try {
    FileUtils.deleteDirectory(outdatedDir);
   } catch (IOException e) {
    LOG.info("Failed to delete outdated search index data directory {}", outdatedDir.getAbsolutePath(), e);
   }
  }
 });
}

代码示例来源:origin: apache/geode

/**
 * Copies the container configuration (found through {@link #getConfiguration()}) to the logging
 * directory specified by {@link #logDir}
 */
public void cleanUp() throws IOException {
 File configDir = new File(getConfiguration().getHome());
 if (configDir.exists()) {
  logger.info("Deleting configuration folder {}", configDir.getAbsolutePath());
  FileUtils.deleteDirectory(configDir);
 }
}

代码示例来源:origin: gocd/gocd

private void deleteExistingAssets(String pluginId) {
    LOGGER.info("Deleting cached static assets for plugin: {}", pluginId);
    try {
      FileUtils.deleteDirectory(new File(pluginStaticAssetsRootDir(pluginId)));
      if (pluginAssetPaths.containsKey(pluginId)) {
        pluginAssetPaths.remove(pluginId);
      }
    } catch (Exception e) {
      LOGGER.error("Failed to delete cached static assets for plugin: {}", pluginId, e);
      ExceptionUtils.bomb(e);
    }
  }
}

代码示例来源:origin: apache/hive

public void init() throws IOException {
 if (localDir.exists()) {
  // TODO: We don't want some random jars of unknown provenance sitting around. Or do we care?
  //       Ideally, we should try to reuse jars and verify using some checksum.
  FileUtils.deleteDirectory(localDir);
 }
 this.resourceDownloader = new ResourceDownloader(conf, localDir.getAbsolutePath());
 workThread.start();
}

代码示例来源:origin: gocd/gocd

private boolean cleanDirectoryIfRepoChanged(File workingDirectory, ConsoleOutputStreamConsumer outputConsumer) {
  boolean cleaned = false;
  try {
    String p4RepoId = p4RepoId();
    File file = new File(workingDirectory, ".cruise_p4repo");
    if (!file.exists()) {
      FileUtils.writeStringToFile(file, p4RepoId, UTF_8);
      return true;
    }
    String existingRepoId = FileUtils.readFileToString(file, UTF_8);
    if (!p4RepoId.equals(existingRepoId)) {
      outputConsumer.stdOutput(format("[%s] Working directory has changed. Deleting and re-creating it.", GoConstants.PRODUCT_NAME));
      FileUtils.deleteDirectory(workingDirectory);
      workingDirectory.mkdirs();
      FileUtils.writeStringToFile(file, p4RepoId, UTF_8);
      cleaned = true;
    }
    return cleaned;
  } catch (IOException e) {
    throw bomb(e);
  }
}

代码示例来源:origin: apache/ignite

/**
 * @throws IOException If IO error happens.
 */
private void clearWorkDir() throws IOException {
  FileUtils.deleteDirectory(new File(WORK_DIR));
}

相关文章

FileUtils类方法