Java File Path Delete deletePath(final File path)

Here you can find the source of deletePath(final File path)

Description

delete Path

License

Open Source License

Declaration

public static void deletePath(final File path) throws IOException 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.*;

public class Main {
    public static void deletePath(final File path) throws IOException {
        deletePathAndRetry(path, 3);/*from   w w  w  . j a v a 2 s.  c o m*/
    }

    private static void deletePathAndRetry(final File path, final int retry) throws IOException {
        try {
            for (final String fn : path.list()) {
                final File f = new File(path, fn);
                if (f.isDirectory()) {
                    deletePath(f);
                }
                if (!f.delete()) {
                    throw new IOException(
                            "Error cleaning up temporary resource. Failed to delete: " + f.getAbsolutePath());
                }
            }
        } catch (IOException io) {
            if (retry > 0) {
                deletePathAndRetry(path, retry - 1);
            } else
                throw io;
        }
    }
}

Related

  1. deleteNonEmptyDirectory(String dirPath)
  2. deleteOldStorageFile(String filepath)
  3. deleteParent(String filePath)
  4. deletePath(File dirPath)
  5. deletePath(File path)
  6. deletePathRecursive(File path)
  7. deleteQuietly(Object path)
  8. deleteRecursive(File path)
  9. deleteRecursive(File path)