且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在Android上删除一个文件夹中的所有文件和文件夹

更新时间:2022-12-30 11:29:04

最简单的方法是使用

Simplest way would be to use FileUtils.deleteDirectory from the Apache Commons IO library.

File dir = new File("root path");
FileUtils.deleteDirectory(dir);

请记住,这也会删除包含目录.

Bear in mind this will also delete the containing directory.

在gradle文件中添加此行以使用Apache

Add this line in gradle file to have Apache

compile 'org.apache.commons:commons-io:1.3.2'