com.sun.enterprise.util.io.FileUtils.deleteFileMaybe()方法的使用及代码示例

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

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

FileUtils.deleteFileMaybe介绍

[英]Wrapper for File.delete This version will return true if the file does not exist when the method returns. Unlike File.delete which returns false if the file does not exist.
[中]文件的包装器。如果方法返回时文件不存在,删除此版本将返回true。不同于文件。delete,如果文件不存在,则返回false。

代码示例

代码示例来源:origin: org.glassfish.main.web/war-util

/**
 * Delete the specified directory, including all of its contents and
 * subdirectories recursively.
 *
 * @param dir File object representing the directory to be deleted
 */
protected static void deleteDir(File dir) {
  String files[] = dir.list();
  if (files == null) {
    files = new String[0];
  }
  for (int i = 0; i < files.length; i++) {
    File file = new File(dir, files[i]);
    if (file.isDirectory()) {
      deleteDir(file);
    } else {
      if (!FileUtils.deleteFileMaybe(file)) {
        logger.log(Level.WARNING,
            LogFacade.UNABLE_TO_DELETE,
            file.toString());
      }
    }
  }
  if (!FileUtils.deleteFileMaybe(dir)) {
    logger.log(Level.WARNING,
        LogFacade.UNABLE_TO_DELETE,
        dir.toString());
  }
}

代码示例来源:origin: org.glassfish.main.admin/admin-util

os.close();
if (!FileUtils.deleteFileMaybe(cacheFile) || !tempFile.renameTo(cacheFile)) {
  if (logger.isLoggable(Level.WARNING)) {
    logger.log(Level.WARNING, AdminLoggerInfo.mCannotWriteCache,
        new Object[] { cacheFile.getPath() });
  if(!FileUtils.deleteFileMaybe(tempFile)) {
    logger.log(Level.FINE, "can't delete file: {0}", tempFile);

代码示例来源:origin: org.glassfish.main.cluster/cluster-cli

private void restoreInstanceDir() {
  File backup = getBackupDir();
  if (backup != null && backup.isDirectory()) {
    File dir = getServerDirs().getServerDir();
    boolean gone = ! FileUtils.deleteFileMaybe(getServerDirs().getServerDir());
    if (!gone || !backup.renameTo(dir)) {
      logger.warning(Strings.get("import.sync.bundle.restoreInstanceDirFailed", backup.getAbsolutePath(), getServerDirs().getServerDir().getAbsolutePath()));
    }
  }
}

相关文章