Java File Path Delete deleteAllFile(String path)

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

Description

Delete all files

License

Apache License

Parameter

Parameter Description
path a parameter

Declaration

public static boolean deleteAllFile(String path) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.io.File;

public class Main {
    /**/*w  w w . j ava 2  s. c  o  m*/
     * Delete all files
     * 
     * @param path
     * @return
     */
    public static boolean deleteAllFile(String path) {
        boolean success = true;

        File file = new File(path);
        if (!file.exists()) {
            success = false;
        }
        if (!file.isDirectory()) {
            success = false;
        }

        if (success) {
            String[] tempList = file.list();
            File temp = null;
            for (int i = 0; i < tempList.length; i++) {
                if (path.endsWith(File.separator)) {
                    temp = new File(path + tempList[i]);
                } else {
                    temp = new File(path + File.separator + tempList[i]);
                }
                if (temp.isFile()) {
                    success &= temp.delete();
                }
            }
        }
        return success;
    }
}

Related

  1. deleteAll(File path)
  2. deleteAllFile(final File dir)
  3. deleteAllFile(String directory)
  4. deleteAllFile(String folderPath)
  5. deleteAllFile(String path)
  6. deleteAllFiles()
  7. deleteAllFiles(File dir)
  8. deleteAllFiles(File directory)
  9. deleteAllFiles(File directory)