Android build文件的删除的方法
作者:zgsHighwin 时间:2022-12-28 12:40:17
本文介绍了Android 删除所有build编译文件,翻译磁盘空间,分享给大家,也给自己留个笔记,具体如下:
public static void main(String[] args) {
//传入一个目录。
deleteFileWithThread("D:\\");
/**
* 这里开了多个线程,提高效率
**/
private static void deleteFileWithThread(String path) {
File file = new File(path);
if (file.isDirectory()) {
File[] files = file.listFiles();
int length = files.length;
for (File outFile : files) {
if (outFile.isDirectory()) {
File[] filesIn = outFile.listFiles();
if (filesIn != null) {
int lengthIn = filesIn.length;
for (int i = 0; i < lengthIn; i++) {
int a = i;
new Thread() {
@Override
public void run() {
delDir(filesIn[a]);
}
}.start();
}
}
}
}
}
}
}
//采用递归的方式去删除文件夹
public static void delDir(File f) {
// 判断是否是一个目录, 不是的话跳过, 直接删除; 如果是一个目录, 先将其内容清空.
if (f.isDirectory()) {
File[] rootFile = f.listFiles();
for (File file : rootFile) {
if (file.isDirectory()) {
if ("build".equals(file.getName())) { //删除build的文件夹和文件夹中的所有内容
System.out.println("fileName delete\t" + file.getAbsolutePath() + "\t" + file.getName());
delete(file);
file.delete();
} else {
delDir(file);
}
}
}
}
}
通过以上的代码就能删除Android 工程下面的所有build的文件夹的内容了。
来源:http://www.jianshu.com/p/9529aa290934
标签:Android,build,删除
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Android AndBase框架使用封装好的函数完成Http请求(三)
2021-09-15 09:49:56
Android App开发中创建Fragment组件的教程
2022-05-18 04:34:38
Apache Commons fileUpload实现文件上传之一
2022-12-06 12:36:48
并行Stream与Spring事务相遇会发生什么?
2022-08-28 15:40:12
![](https://img.aspxhome.com/file/2023/4/85944_0s.webp)
Android实现中国象棋附源码下载
2023-12-20 17:09:10
基于C#生成随机数示例
2023-06-27 08:40:17
JAVA如何定义构造函数过程解析
2023-11-04 08:15:09
![](https://img.aspxhome.com/file/2023/7/58477_0s.png)
android自定义进度条渐变圆形
2022-07-15 02:04:14
![](https://img.aspxhome.com/file/2023/7/138037_0s.png)
Android使用Service实现简单音乐播放实例
2023-11-30 20:03:23
![](https://img.aspxhome.com/file/2023/2/138422_0s.png)
c#如何实现接口事件
2023-10-02 18:31:28
Java超详细分析@Autowired原理
2023-11-25 05:37:44
![](https://img.aspxhome.com/file/2023/9/60059_0s.png)
Java毕业设计实战之在线蛋糕销售商城的实现
2022-06-06 14:25:39
![](https://img.aspxhome.com/file/2023/5/71815_0s.png)
C#如何访问共享文件夹或者磁盘
2023-11-08 09:43:44
js 交互在Flutter 中使用 webview_flutter
2023-07-20 22:40:14
![](https://img.aspxhome.com/file/2023/5/91785_0s.jpg)
android使用gesturedetector手势识别示例分享
2023-08-08 15:06:11
SpringBoot整合Thymeleaf小项目及详细流程
2021-08-13 16:32:08
![](https://img.aspxhome.com/file/2023/0/80890_0s.png)
SpringBoot实现任意位置获取HttpServletRequest对象
2023-07-07 10:26:40
Java调用明华RF读写器DLL文件过程解析
2022-12-17 04:31:06
![](https://img.aspxhome.com/file/2023/2/105932_0s.png)
一文详解无痕埋点在Android中的实现
2022-06-30 07:53:18
![](https://img.aspxhome.com/file/2023/3/137813_0s.jpg)
解决SpringBoot框架因post数据量过大没反应问题(踩坑)
2023-11-28 11:59:30