Java File Path Delete delete(String path)

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

Description

delete

License

Open Source License

Declaration

public static void delete(String path) 

Method Source Code

//package com.java2s;
/**//from w  w  w . java 2 s.c  o  m
 * Copyright(c) 2005 Dragonfly - created by FengChun
 * All Rights Reserved.
 * 
 * @license: Dragonfly Common License
 * @date 2005-5-16
 */

import java.io.File;

public class Main {
    public static void delete(String path) {
        File f = new File(path);
        if (!f.exists())
            return;
        if (f.isDirectory()) {
            if (f.listFiles().length == 0) {
                f.delete();
            } else {
                File delFile[] = f.listFiles();
                int i = f.listFiles().length;
                for (int j = 0; j < i; j++) {
                    if (delFile[j].isDirectory()) {
                        delete(delFile[j].getAbsolutePath());
                    }
                    delFile[j].delete();
                }
            }
        } else {
            f.delete();
        }
    }
}

Related

  1. delete(String filePath)
  2. delete(String filePath)
  3. delete(String filePath)
  4. delete(String filePath)
  5. delete(String filePath, boolean recursive)
  6. delete(String path)
  7. delete(String path)
  8. delete(String path)
  9. deleteAll(File path)