java中删除特定后缀名文件


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();// 删除文件}
                }
            }
        }

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM