Java File Path Delete deleteFileOrDirectory(String path)

Here you can find the source of deleteFileOrDirectory(String path)

Description

delete File Or Directory

License

Open Source License

Declaration

public static void deleteFileOrDirectory(String path) 

Method Source Code


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

public class Main {
    public static void deleteFileOrDirectory(String path) {
        deleteFileOrDirectory(new File(path));
    }/*from w w  w. java 2s  .c  o  m*/

    public static void deleteFileOrDirectory(File file) {
        if (!file.exists())
            return;

        if (!file.isDirectory()) {
            file.delete();
            return;
        }

        File directory = file;

        File[] children = directory.listFiles();

        for (File child : children) {
            if (child.isDirectory())
                deleteFileOrDirectory(child);
            else
                child.delete();
        }

        directory.delete();
    }
}

Related

  1. deleteFile(String strPath, String fileName)
  2. DeleteFileFolder(String path)
  3. deleteFileFromDisk(String name, String path)
  4. deleteFileIfExists(String path)
  5. deleteFileOrDirectory(String path)
  6. deleteFiles(final File pathname)
  7. deleteFiles(String actionPath, String filePath)
  8. deleteFiles(String filePath)
  9. deleteFilesInDirectory(File path)