public static boolean recursiveClean(final File fileToRemove) {
        if (fileToRemove == null)
            return true;

        Boolean fileExists = Boolean.FALSE;
        final File f_fileToRemove = fileToRemove;

        try {
            fileExists = AccessController.doPrivileged(new java.security.PrivilegedExceptionAction<Boolean>() {
                @Override
                public Boolean run() throws Exception {
                    if (f_fileToRemove.exists()) {
                        return Boolean.TRUE;
                    }
                    return Boolean.FALSE;
                }
            });
        } catch (Exception ex) {
        }

        if (fileExists != null && !(fileExists.booleanValue()))

            //if (!fileToRemove.exists())
            return true;

        boolean success = true;

        Boolean fileIsDirectory = null;
        //final File f_fileToRemove = fileToRemove;
        try {
            fileIsDirectory = AccessController.doPrivileged(new java.security.PrivilegedExceptionAction<Boolean>() {
                @Override
                public Boolean run() throws Exception {
                    if (f_fileToRemove.isDirectory()) {
                        return Boolean.TRUE;
                    }
                    return Boolean.FALSE;
                }
            });
        } catch (Exception ex) {
        }

        if (fileIsDirectory != null && fileIsDirectory.booleanValue()) {
            //if (fileToRemove.isDirectory()) {
            File[] files = fileToRemove.listFiles();
            // listFiles may return null if we lack read permissions
            if (files == null)
                return false;
            for (File file : files) {
                if (file.isDirectory()) {
                    success |= recursiveClean(file);
                } else if ((file.getName().equals(BootstrapConstants.S_LOCK_FILE) &&
                            fileToRemove.getName().equals(BootstrapConstants.LOC_AREA_NAME_WORKING))
                           ||
                           ((fileToRemove.getName().equals(BootstrapConstants.LOC_AREA_NAME_WORKING))) &&
                              (file.getName().equals(BootstrapConstants.SERVER_RUNNING_FILE))) {
                    // skip/preserve workarea/.sLock and workarea/.sRunning files
                } else {
                    success |= file.delete();
                }
            }
            files = fileToRemove.listFiles();
            if (files.length == 0)
                success |= fileToRemove.delete();
        } else {

            Boolean successful_delete = Boolean.TRUE;
            final File ftr = fileToRemove;
            try {
                successful_delete = AccessController.doPrivileged(new java.security.PrivilegedExceptionAction<Boolean>() {
                    @Override
                    public Boolean run() throws Exception {
                        Boolean s = ftr.delete();
                        return s;
                    }
                });
            } catch (Exception ex) {
            }

            //success |= fileToRemove.delete();
            success |= successful_delete.booleanValue();
        }
        return success;
    }
public static boolean recursiveClean ( final File fileToRemove ) { if ( fileToRemove == null ) return true ; Boolean fileExists = Boolean . FALSE ; final File f_fileToRemove = fileToRemove ; try { fileExists = AccessController . doPrivileged ( new java . security . PrivilegedExceptionAction < Boolean > ( ) { @ Override public Boolean run ( ) throws Exception { if ( f_fileToRemove . exists ( ) ) { return Boolean . TRUE ; } return Boolean . FALSE ; } } ) ; } catch ( Exception ex ) { } if ( fileExists != null && ! ( fileExists . booleanValue ( ) ) ) return true ; boolean success = true ; Boolean fileIsDirectory = null ; try { fileIsDirectory = AccessController . doPrivileged ( new java . security . PrivilegedExceptionAction < Boolean > ( ) { @ Override public Boolean run ( ) throws Exception { if ( f_fileToRemove . isDirectory ( ) ) { return Boolean . TRUE ; } return Boolean . FALSE ; } } ) ; } catch ( Exception ex ) { } if ( fileIsDirectory != null && fileIsDirectory . booleanValue ( ) ) { File [ ] files = fileToRemove . listFiles ( ) ; if ( files == null ) return false ; for ( File file : files ) { if ( file . isDirectory ( ) ) { success |= recursiveClean ( file ) ; } else if ( ( file . getName ( ) . equals ( BootstrapConstants . S_LOCK_FILE ) && fileToRemove . getName ( ) . equals ( BootstrapConstants . LOC_AREA_NAME_WORKING ) ) || ( ( fileToRemove . getName ( ) . equals ( BootstrapConstants . LOC_AREA_NAME_WORKING ) ) ) && ( file . getName ( ) . equals ( BootstrapConstants . SERVER_RUNNING_FILE ) ) ) { } else { success |= file . delete ( ) ; } } files = fileToRemove . listFiles ( ) ; if ( files . length == 0 ) success |= fileToRemove . delete ( ) ; } else { Boolean successful_delete = Boolean . TRUE ; final File ftr = fileToRemove ; try { successful_delete = AccessController . doPrivileged ( new java . security . PrivilegedExceptionAction < Boolean > ( ) { @ Override public Boolean run ( ) throws Exception { Boolean s = ftr . delete ( ) ; return s ; } } ) ; } catch ( Exception ex ) { } success |= successful_delete . booleanValue ( ) ; } return success ; }
Recursively delete directory: used to clean up for clean start.

@param fileToRemove
Name of file/directory to delete. If the File is a directory,
all sub-directories and files will also be deleted except for
the server lock and server running file.

This method will return false if the file can not be read or deleted.

@return true if the clean succeeded, false otherwise