Java File Delete delete(File f)

Here you can find the source of delete(File f)

Description

Delete a file.

License

Open Source License

Parameter

Parameter Description
f the file to delete

Exception

Parameter Description
IOException if the file can't be deleted.

Declaration

private static void delete(File f) throws IOException 

Method Source Code


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

import java.io.File;

import java.io.IOException;

public class Main {
    /**/*from  w  ww.ja v  a  2s  . c  o  m*/
     * Delete a file.  This method will retry the delete up to 5 times, sleeping for one second between retries.
     * This is because sometimes, especially with smaller imports, the cleanup starts happening before vault has closed
     * all of it's file locks.  The retry behavior makes a best effort to properly cleanup when that happens.
     * @param f the file to delete
     * @throws IOException if the file can't be deleted.
     */
    private static void delete(File f) throws IOException {
        boolean isDeleted = f.delete();
        for (int i = 0; i < 4 && !isDeleted; i++) {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new IOException("Failed to delete file: " + f, e);
            }
            isDeleted = f.delete();
        }

        if (!isDeleted) {
            throw new IOException("Failed to delete file: " + f);
        }
    }
}

Related

  1. delete(File f)
  2. delete(File f)
  3. delete(File f)
  4. delete(File f)
  5. delete(File f)
  6. delete(File f)
  7. delete(File f)
  8. delete(File f)
  9. delete(File f)