Skip to content

Instantly share code, notes, and snippets.

@beyoung
Created March 16, 2015 09:30
Show Gist options
  • Save beyoung/07084eea21acb64f3d38 to your computer and use it in GitHub Desktop.
Save beyoung/07084eea21acb64f3d38 to your computer and use it in GitHub Desktop.
java删除一个目录及其下的所有文件
/*
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