org.scijava.util.FileUtils.deleteRecursively()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(4.9k)|赞(0)|评价(0)|浏览(126)

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

FileUtils.deleteRecursively介绍

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

代码示例

代码示例来源:origin: org.scijava/scripting-java

/**
   * Cleans up the project, if it was only temporary.
   */
  private void cleanup() {
    if (err != null) err.close();
    if (err != null) err.close();
    if (temporaryDirectory != null &&
      !FileUtils.deleteRecursively(temporaryDirectory))
    {
      temporaryDirectory.deleteOnExit();
    }
  }
}

代码示例来源:origin: org.scijava/scijava-common

/**
 * Deletes a directory recursively.
 * 
 * @param directory The directory to delete.
 * @return whether it succeeded (see also {@link File#delete()})
 */
public static boolean deleteRecursively(final File directory) {
  if (directory == null) return true;
  final File[] list = directory.listFiles();
  if (list == null) return true;
  for (final File file : list) {
    if (file.isFile()) {
      if (!file.delete()) return false;
    }
    else if (file.isDirectory()) {
      if (!deleteRecursively(file)) return false;
    }
  }
  return directory.delete();
}

代码示例来源:origin: scijava/scijava-common

/**
 * Deletes a directory recursively.
 * 
 * @param directory The directory to delete.
 * @return whether it succeeded (see also {@link File#delete()})
 */
public static boolean deleteRecursively(final File directory) {
  if (directory == null) return true;
  final File[] list = directory.listFiles();
  if (list == null) return true;
  for (final File file : list) {
    if (file.isFile()) {
      if (!file.delete()) return false;
    }
    else if (file.isDirectory()) {
      if (!deleteRecursively(file)) return false;
    }
  }
  return directory.delete();
}

代码示例来源:origin: scijava/scijava-common

if (!FileUtils.deleteRecursively(file)) {

代码示例来源:origin: org.scijava/scijava-common

if (!FileUtils.deleteRecursively(file)) {

代码示例来源:origin: scijava/scijava-common

@AfterClass
public static void tearDown() {
  FileUtils.deleteRecursively(scriptsDir);
}

代码示例来源:origin: scijava/scijava-common

@Test
public void testUnpackedClass() throws IOException {
  final File tmpDir = createTemporaryDirectory("class-utils-test-");
  final String path = getClass().getName().replace('.', '/') + ".class";
  final File classFile = new File(tmpDir, path);
  assertTrue(classFile.getParentFile().exists() ||
    classFile.getParentFile().mkdirs());
  copy(getClass().getResource("/" + path).openStream(),
    new FileOutputStream(classFile), true);
  final ClassLoader classLoader =
    new URLClassLoader(new URL[] { tmpDir.toURI().toURL() }, null);
  final URL location = ClassUtils.getLocation(getClass().getName(),
    classLoader);
  assertEquals(tmpDir, FileUtils.urlToFile(location));
  FileUtils.deleteRecursively(tmpDir);
}

代码示例来源:origin: scijava/scijava-common

/** Tests {@link Types#location} with a class on the file system. */
@Test
public void testLocationUnpackedClass() throws IOException {
  final File tmpDir = createTemporaryDirectory("class-utils-test-");
  final String path = getClass().getName().replace('.', '/') + ".class";
  final File classFile = new File(tmpDir, path);
  assertTrue(classFile.getParentFile().exists() ||
    classFile.getParentFile().mkdirs());
  copy(getClass().getResource("/" + path).openStream(),
    new FileOutputStream(classFile), true);
  final ClassLoader classLoader =
    new URLClassLoader(new URL[] { tmpDir.toURI().toURL() }, null);
  final Class<?> c = Types.load(getClass().getName(), classLoader);
  final URL location = Types.location(c);
  assertEquals(tmpDir, FileUtils.urlToFile(location));
  FileUtils.deleteRecursively(tmpDir);
}

代码示例来源:origin: scijava/scijava-common

@Test
public void testGetAllVersions() throws IOException {
  final String withClassifier = "miglayout-3.7.3.1-swing.jar";
  final String withoutClassifier = "miglayout-3.7.3.1.jar";
  final File tmp = createTemporaryDirectory("delete-other-");
  try {
    writeEmptyFile(new File(tmp, withClassifier));
    writeEmptyFile(new File(tmp, withoutClassifier));
    assertArrayEquals(new File[] { new File(tmp, withClassifier) },
      FileUtils.getAllVersions(tmp, withClassifier));
    assertArrayEquals(new File[] { new File(tmp, withoutClassifier) },
      FileUtils.getAllVersions(tmp, withoutClassifier));
  }
  finally {
    FileUtils.deleteRecursively(tmp);
  }
}

代码示例来源:origin: scijava/scijava-common

/** Tests {@link ScriptInfo#getVersion()}. */
@Test
public void testVersion() throws IOException {
  final String script = "" + //
    "% @LogService log\n" + //
    "% @OUTPUT int output";
  // write script to a temporary directory on disk
  final File tmpDir = TestUtils.createTemporaryDirectory("script-info-test-");
  final String path = "hello.bsizes";
  final File scriptFile = new File(tmpDir, path);
  FileUtils.writeFile(scriptFile, DigestUtils.bytes(script));
  // verify that the version is correct
  final ScriptInfo info = new ScriptInfo(context, scriptFile);
  final String version = info.getVersion();
  final String sha1 = "28f4a2880d604774ac5d604d35f431047a087c9e";
  assertTrue(version.matches("^" + sha1 + "$"));
  // clean up the temporary directory
  FileUtils.deleteRecursively(tmpDir);
}

代码示例来源:origin: scijava/scijava-common

FileUtils.deleteRecursively(cacheDir);

相关文章