Java Delete File deleteFile(String filename)

Here you can find the source of deleteFile(String filename)

Description

delete File

License

Open Source License

Declaration

public static void deleteFile(String filename) 

Method Source Code


//package com.java2s;
import java.io.*;

public class Main {
    public static void deleteFile(String filename) {
        deleteFile(new File(filename));
    }// w  w  w  . ja  v a 2 s  . c  o m

    public static void deleteFile(File file) {
        if (!file.exists())
            return;
        if (!file.delete())
            throw new RuntimeException("Could not delete '" + file.getAbsoluteFile() + "'");
        waitUntilFileDeleted(file);
    }

    private static void waitUntilFileDeleted(File file) {
        int i = 10;
        while (file.exists()) {
            if (--i <= 0) {
                System.out.println("Breaking out of delete wait");
                break;
            }
            try {
                Thread.sleep(500);
            } catch (InterruptedException e) {
            }
        }
    }
}

Related

  1. deleteFile(String fileName)
  2. deleteFile(String fileName)
  3. deleteFile(String fileName)
  4. deleteFile(String fileName)
  5. deleteFile(String fileName)
  6. deleteFile(String filename)
  7. deleteFile(String FileName)
  8. deleteFile(String fileName)
  9. deleteFile(String filename)