批量重命名签名好以后的文件

应用加固后,再次签名的时候(使用了Qihoo360 Apk Signer),签名后的文件名类似这样AS18_signed_Aligned.apk,没有携带版本号,如果那么多渠道一个一个手动去改,麻烦不说还容易错。
所以就自己写个批量重命名的工具类。
重命名前文件名为AS18_signed_Aligned.apk,
重命名后文件名为AS18_signed_输入的内容.apk

import java.io.File;
import java.util.Scanner;

public class Test {

    private static String sVersionName;
    private static String sReplaceName = "Aligned";

    public static void main(String[] ar) {


//        File file = new File("");
//        System.out.println(file.getAbsoluteFile());
        sVersionName =  getVersionCode();

        File directory = getCurrentDirectory();

        getFileName(directory);

    }

    private static File getCurrentDirectory() {
        File file = new File("");
        System.out.println(file.getAbsoluteFile());
        return file.getAbsoluteFile();
    }

    private static String getVersionCode() {
        System.out.println("input your version code ,like [v1.1.8]");
        Scanner scanner = new Scanner(System.in);
        String code = scanner.next();
        System.out.println("input version code success , code is = " + sVersionName);
        return code;
    }

    private static void getFileName(File file) {
        if (file == null) {
            System.out.println("file == null");
            return;
        }

        if (sVersionName == null) {
            System.out.println("sVersionName == null");
            return;
        }
        if (file.isDirectory()) {
            File[] files = file.listFiles();
            if (files == null) {
                System.out.println("files == null");
                return;
            }

            System.out.println("files.length  =  " + files.length);
            for (int i = 0; i < files.length; i++) {
                getFileName(files[i]);
            }
        } else if (file.isFile()) {

            String name = file.getName();
            if (name.contains(sReplaceName)) {
                String path = file.getAbsolutePath().replace(sReplaceName, sVersionName);
                boolean aligned = file.renameTo(new File(path));
                if (aligned) {
                    System.out.println("rename success, path : " + path);
                } else {
                    System.out.println("warning !! rename failure, path : " + path);
                }
            }

        } else {
            System.out.println("file is not Directory or File");
        }
    }
}

原文件.png
运行.png
重命名后文件.png
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 173,523评论 25 708
  • 写在开头 距离上一篇博客已经好几个月没有更新博客了。在这几个月中,经历了过年,年后综合征,离职,适应新工作环境等等...
    niknowzcd阅读 1,616评论 0 3
  • 参考什么是 Android 签名机制,Bluebox Security 发现的漏洞有何威胁? Android应用程...
    合肥黑阅读 2,096评论 1 16
  • 这是一组十进制的数字,换成二进制也是如此。这组数字在2014年7月31日24:00才具备意义—一千万现金月度业绩记...
    Andylee阅读 513评论 1 1
  • 充实的一天,完全没有纠结昨天的事情。学习确实是让自己受益的事情,继续继续。感赏老公能有意识的出去走走,并主动帮我送...
    叛逆的榴莲阅读 192评论 0 0