src/main/java/org/jboss/util/file/Files.java
/** Delete a file, or a directory and all of its contents.
    *
    * @param dir The directory or file to delete.
    * @return True if all delete operations were successfull.
    */
Delete a file, or a directory and all of its contents.
@param dir The directory or file to delete.
@return True if all delete operations were successfull.
Delete a file or a directory and all of its contents . @param dir The directory or file to delete . @return True if all delete operations were successfull .
public static boolean delete(final File dir)
   {
      boolean success = true;
      File files[] = dir.listFiles();
      if (files != null)
      {
         for (int i = 0; i < files.length; i++)
         {
            File f = files[i];
            if( f.isDirectory() == true )
            {
               if( delete(f) == false )
               {
                  success = false;
                  log.debug("Failed to delete dir: "+f.getAbsolutePath());
               }
            }
            else if( f.delete() == false )
            {
               success = false;
               log.debug("Failed to delete file: "+f.getAbsolutePath());
            }
         }
      }
      if( dir.delete() == false )
      {
         success = false;
         log.debug("Failed to delete dir: "+dir.getAbsolutePath());
      }
      return success;
   }
public static boolean delete ( final File dir ) { boolean success = true ; File files [ ] = dir . listFiles ( ) ; if ( files != null ) { for ( int i = 0 ; i < files . length ; i ++ ) { File f = files [ i ] ; if ( f . isDirectory ( ) == true ) { if ( delete ( f ) == false ) { success = false ; log . debug ( "Failed to delete dir: " + f . getAbsolutePath ( ) ) ; } } else if ( f . delete ( ) == false ) { success = false ; log . debug ( "Failed to delete file: " + f . getAbsolutePath ( ) ) ; } } } if ( dir . delete ( ) == false ) { success = false ; log . debug ( "Failed to delete dir: " + dir . getAbsolutePath ( ) ) ; } return success ; }
Delete a file, or a directory and all of its contents.
Delete a file or a directory and all of its contents .
// delete the directory and all of its contents. // delete each file in the directory // finally delete the directory