Java Utililty Methods Wait Until File Deleted

List of utility methods to do Wait Until File Deleted

Description

The list of methods to do Wait Until File Deleted are organized into topic(s).

Method

voidwaitUntilFileDeleted(File file)
wait Until File Deleted
int i = 10;
while (file.exists()) {
    if (--i <= 0) {
        System.out.println("Breaking out of delete wait");
        break;
    try {
        Thread.sleep(500);
...
booleanwaitUntilFileDeleted(File file)
Wait until the file is _really_ deleted on file system.
int count = 0;
int delay = 10; 
int maxRetry = DELETE_MAX_WAIT / delay;
int time = 0;
while (count < maxRetry) {
    try {
        count++;
        Thread.sleep(delay);
...
booleanwaitUntilFileDeleted(File file)
Wait until the file is _really_ deleted on file system.
if (DELETE_DEBUG) {
    System.out.println();
    System.out.println("WARNING in test: " + getTestName());
    System.out.println("   - problems occured while deleting " + file);
    printJdtStackTrace(null, 1);
    printFileInfo(file.getParentFile(), 1, -1); 
    System.out.print("   - wait for (" + DELETE_MAX_WAIT + "ms max): ");
int count = 0;
int delay = 10; 
int maxRetry = DELETE_MAX_WAIT / delay;
int time = 0;
while (count < maxRetry) {
    try {
        count++;
        Thread.sleep(delay);
        time += delay;
        if (time > DELETE_MAX_TIME)
            DELETE_MAX_TIME = time;
        if (DELETE_DEBUG)
            System.out.print('.');
        if (file.exists()) {
            if (file.delete()) {
                if (DELETE_DEBUG) {
                    System.out.println();
                    System.out.println("   => file really removed after " + time + "ms (max="
                            + DELETE_MAX_TIME + "ms)");
                    System.out.println();
                return true;
        if (isFileDeleted(file)) {
            if (DELETE_DEBUG) {
                System.out.println();
                System.out.println(
                        "   => file disappeared after " + time + "ms (max=" + DELETE_MAX_TIME + "ms)");
                System.out.println();
            return true;
        if (count >= 10 && delay <= 100) {
            count = 1;
            delay *= 10;
            maxRetry = DELETE_MAX_WAIT / delay;
            if ((DELETE_MAX_WAIT % delay) != 0) {
                maxRetry++;
    } catch (InterruptedException ie) {
        break; 
if (!DELETE_DEBUG) {
    System.out.println();
    System.out.println("WARNING in test: " + getTestName());
    System.out.println("   - problems occured while deleting " + file);
    printJdtStackTrace(null, 1);
    printFileInfo(file.getParentFile(), 1, -1); 
System.out.println();
System.out.println("   !!! ERROR: " + file + " was never deleted even after having waited "
        + DELETE_MAX_TIME + "ms!!!");
System.out.println();
return false;
booleanwaitUntilFileDeleted(File file)
Wait until the file is _really_ deleted on file system.
if (DELETE_DEBUG) {
    System.out.println();
    System.out.println("WARNING in test: " + getTestName());
    System.out.println("   - problems occured while deleting " + file);
    printRdtCoreStackTrace(null, 1);
    printFileInfo(file.getParentFile(), 1, -1); 
    System.out.print("   - wait for (" + DELETE_MAX_WAIT + "ms max): ");
int count = 0;
int delay = 10; 
int maxRetry = DELETE_MAX_WAIT / delay;
int time = 0;
while (count < maxRetry) {
    try {
        count++;
        Thread.sleep(delay);
        time += delay;
        if (time > DELETE_MAX_TIME)
            DELETE_MAX_TIME = time;
        if (DELETE_DEBUG)
            System.out.print('.');
        if (file.exists()) {
            if (file.delete()) {
                if (DELETE_DEBUG) {
                    System.out.println();
                    System.out.println("   => file really removed after " + time + "ms (max="
                            + DELETE_MAX_TIME + "ms)");
                    System.out.println();
                return true;
        if (isFileDeleted(file)) {
            if (DELETE_DEBUG) {
                System.out.println();
                System.out.println(
                        "   => file disappeared after " + time + "ms (max=" + DELETE_MAX_TIME + "ms)");
                System.out.println();
            return true;
        if (count >= 10 && delay <= 100) {
            count = 1;
            delay *= 10;
            maxRetry = DELETE_MAX_WAIT / delay;
            if ((DELETE_MAX_WAIT % delay) != 0) {
                maxRetry++;
    } catch (InterruptedException ie) {
        break; 
if (!DELETE_DEBUG) {
    System.out.println();
    System.out.println("WARNING in test: " + getTestName());
    System.out.println("   - problems occured while deleting " + file);
    printRdtCoreStackTrace(null, 1);
    printFileInfo(file.getParentFile(), 1, -1); 
System.out.println();
System.out.println("   !!! ERROR: " + file + " was never deleted even after having waited "
        + DELETE_MAX_TIME + "ms!!!");
System.out.println();
return false;