Created
March 16, 2015 09:30
-
-
Save beyoung/07084eea21acb64f3d38 to your computer and use it in GitHub Desktop.
java删除一个目录及其下的所有文件
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Method 1 | |
*/ | |
import org.apache.commons.io.FileUtils; | |
File f = new File("/dir"); | |
FileUtils.cleanDirectory(f); | |
/* | |
Method 2 | |
*/ | |
import java.io.File | |
File dir=new File("/dr"); | |
for (File file : dir.listFiles()) | |
if (!file.isDirectory()) | |
file.delete(); | |
dir.delete(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment