Here you can find the source of delete(String filePath)
public static boolean delete(String filePath)
//package com.java2s; /*/* ww w. ja va2 s .c o m*/ * Copyright 2017 Alibaba.com All right reserved. This software is the * confidential and proprietary information of Alibaba.com ("Confidential * Information"). You shall not disclose such Confidential Information and shall * use it only in accordance with the terms of the license agreement you entered * into with Alibaba.com. */ import java.io.File; public class Main { public static boolean delete(File file) { if (file.isFile()) { return file.delete(); } else { boolean flag = true; for (File item : file.listFiles()) { flag = flag & delete(item); } flag = flag & file.delete(); return flag; } } public static boolean delete(String filePath) { File file = new File(filePath); return delete(file); } }