码迷,mamicode.com
首页 > 编程语言 > 详细

java中删除特定后缀名文件

时间:2016-06-12 10:53:25      阅读:396      评论:0      收藏:0      [点我收藏+]

标签:

String path = Environment.getExternalStorageDirectory()
                        .getPath() + AppConstant.FILE_PATH + "/" + apkName ;
                File file = new File(path);
deleteApk(path);
/**
         * 删除其他版本安装包
         */
        public void deleteApk(String abpath) {
            String[] ss = abpath.split("/");
            String name = ss[ss.length - 1];
            String path = abpath.replace("/" + name, "");

            File file = new File(path);// 里面输入特定目录
            File temp = null;
            File[] filelist = file.listFiles();
            for (int i = 0; i < filelist.length; i++) {
                temp = filelist[i];
                if (temp.getName().endsWith("apk") && !temp.getName().endsWith(name))// 获得文件名,如果后缀为“”,这个你自己写,就删除文件
                {
                    temp.delete();// 删除文件}
                }
            }
        }

 

java中删除特定后缀名文件

标签:

原文地址:http://www.cnblogs.com/chenlong-50954265/p/5576693.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!