Here you can find the source of deleteAllFilesInDirectory(String path)
public static boolean deleteAllFilesInDirectory(String path)
//package com.java2s; //License from project: Open Source License import java.io.File; public class Main { /**/*from w w w .ja va 2 s . c om*/ * deletes entire contents of a folder. Returns true if deletion successful, false otherwise * * comment added by thomas: * doesn't delete folders that contain nonempty folders */ public static boolean deleteAllFilesInDirectory(String path) { File folder = new File(path); if (folder != null && folder.exists() && folder.isDirectory()) { File[] files = folder.listFiles(); if (files != null) { for (int i = 0; i < files.length; i++) { files[i].delete(); } } return true; } return false; } public static boolean exists(String path, String fileNameWithoutFullPath) { String filePath = getFileNameWithPath(path, fileNameWithoutFullPath); return exists(filePath); } public static boolean exists(String fileNameWithFullPath) { File file = new File(fileNameWithFullPath); return file.exists(); } /** * Deletes a File Object. */ public static File delete(File file) { file.delete(); return file; } /** * Deletes a File from an url. */ public static boolean delete(String fileNameWithFullPath) { File file = new File(fileNameWithFullPath); return file.delete(); } public static String getFileNameWithPath(String path, String fileNameWithoutFullPath) { return path + File.separator + fileNameWithoutFullPath; } }