com.google.common.io.Files.deleteDirectoryContents()方法的使用及代码示例

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

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

Files.deleteDirectoryContents介绍

[英]Deletes all the files within a directory. Does not delete the directory itself.

If the file argument is a symbolic link or there is a symbolic link in the path leading to the directory, this method will do nothing. Symbolic links within the directory are not followed.
[中]删除目录中的所有文件。不删除目录本身。
如果file参数是一个符号链接,或者指向目录的路径中有一个符号链接,则此方法将不起任何作用。不遵循目录中的符号链接。

代码示例

代码示例来源:origin: linkedin/indextank-engine

Files.deleteDirectoryContents(root.getPreviousPath().getCanonicalFile());
logger.info("Moving current data to previous directory...");
moveMigrableFiles(root.getPath(), root.getPreviousPath());

代码示例来源:origin: com.google.guava/guava-io

/**
 * Deletes a file or directory and all contents recursively.
 *
 * <p>If the file argument is a symbolic link the link will be deleted
 * but not the target of the link. If the argument is a directory,
 * symbolic links within the directory will not be followed.
 *
 * @param file the file to delete
 * @throws IOException if an I/O error occurs
 * @see #deleteDirectoryContents
 */
public static void deleteRecursively(File file) throws IOException {
 if (file.isDirectory()) {
  deleteDirectoryContents(file);
 }
 if (!file.delete()) {
  throw new IOException("Failed to delete " + file);
 }
}

代码示例来源:origin: com.atlassian.bundles/guava

/**
 * Deletes a file or directory and all contents recursively.
 *
 * <p>If the file argument is a symbolic link the link will be deleted
 * but not the target of the link. If the argument is a directory,
 * symbolic links within the directory will not be followed.
 *
 * @param file the file to delete
 * @throws IOException if an I/O error occurs
 * @see #deleteDirectoryContents
 */
public static void deleteRecursively(File file) throws IOException {
 if (file.isDirectory()) {
  deleteDirectoryContents(file);
 }
 if (!file.delete()) {
  throw new IOException("Failed to delete " + file);
 }
}

相关文章