多渠道打包 之 批量重名文件名

本文介绍了一个用于批量重命名360加固后的APK文件的Java程序实现。该程序能够读取特定目录下的文件,并按照预设的渠道数组进行重命名,输出到指定目录。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


针对360加固后文件重命名

  • 原始文件名:android_v2.2.3_app_223_1_jiagu_sign.apk

  • 输出结果:android_v2.2.3_baidu.apk

public class Main {

    private static String IN_FILE_PATH = "F:\\ApkVersion\\2.2.3\\";//目标文件地址
    private static String OUT_FILE_PATH = "F:\\ApkVersion\\2.2.3\\";//输出文件地址
    private static String APP_VERSION = "v2.2.3";//版本号
    //渠道数组:顺序与加固渠道码一致
    private static String[] channels = new String[]{
            "baidu",
            "360",
            "qq",
            "oppo",
            "vivo"};

    public static void main(String[] args) {
        // write your code here

        //批量重命名文件
        updateFileName(IN_FILE_PATH,OUT_FILE_PATH);
    }

    private static void updateFileName(String dirPath,String outPath) {
        File file = new File(dirPath);

        //判断文件目录是否存在,且是文件目录
        if (file.exists() && file.isDirectory()) {

            //获取文件列表
            File[] childFiles = file.listFiles();

            String path = file.getAbsolutePath();
            System.out.print("path =" + path);


            for (File childFile : childFiles) {
                //如果是文件
                if (childFile.isFile()) {
                    String oldName = childFile.getName();
                    System.out.print("\noldName =" + oldName);

                    String[] splitResult = oldName.split("_");

                    String newName;
                    for (int i = 0; i < splitResult.length; i++) {

                        System.out.print("\nsplitResult =" + splitResult[i]);

                    }

                    int num = Integer.valueOf(splitResult[4]);

                    newName = "android_" + APP_VERSION + "_" + channels[num - 1] + ".apk";

                    ifDirExists(new File(outPath));

                    boolean update = childFile.renameTo(new File(OUT_FILE_PATH + newName));

                    if (update) {
                        System.out.print("\n第" + num + "个文件重命名成功" + "\n结果: " + childFile.getName());
                    }

                }
                System.out.print("\n文件重命名成功" + "\n结果: " + childFile.getName());

            }
        }

    }

    //判断文件夹是否存在
    public static void ifDirExists(File dirFile) {
        if (dirFile.exists()) {
            if (dirFile.isDirectory()) {
                System.out.println("\ndir exists");
            } else {
                System.out.println("\nthe same name file exists, can not create dir");
            }
        } else {
            System.out.println("dir not exists, create it ...");
            dirFile.mkdir();
        }
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值