org.codehaus.plexus.util.FileUtils.deleteFile()方法的使用及代码示例

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

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

FileUtils.deleteFile介绍

[英]Accommodate Windows bug encountered in both Sun and IBM JDKs. Others possible. If the delete does not work, call System.gc(), wait a little and try again.
[中]适应Sun和IBM JDK中遇到的Windows错误。其他可能的。如果删除不起作用,请呼叫系统。gc(),请稍等,然后重试。

代码示例

代码示例来源:origin: org.codehaus.plexus/plexus-utils

/**
 * Delete a file. If file is directory delete it and all sub-directories.
 *
 * @param file a file
 * @throws IOException if any
 */
public static void forceDelete( final File file )
  throws IOException
{
  if ( file.isDirectory() )
  {
    deleteDirectory( file );
  }
  else
  {
    /*
     * NOTE: Always try to delete the file even if it appears to be non-existent. This will ensure that a
     * symlink whose target does not exist is deleted, too.
     */
    boolean filePresent = file.getCanonicalFile().exists();
    if ( !deleteFile( file ) && filePresent )
    {
      final String message = "File " + file + " unable to be deleted.";
      throw new IOException( message );
    }
  }
}

代码示例来源:origin: org.apache.servicemix.kernel.gshell/org.apache.servicemix.kernel.gshell.core

/**
 * Delete a file. If file is directory delete it and all sub-directories.
 */
public static void forceDelete( final File file )
  throws IOException
{
  if ( !( file.exists() || file.getAbsoluteFile().exists() || file.getCanonicalFile().exists() ) )
  {
    return;
  }
  if ( file.isDirectory() )
  {
    deleteDirectory( file );
  }
  else
  {
    if ( !deleteFile( file ) )
    {
      final String message = "File " + file + " unable to be deleted.";
      throw new IOException( message );
    }
  }
}

相关文章