牙叔教程 简单易懂
/* * @version: 1.0 * @Date: 2022-01-18 12:40:45 * @LastEditTime: 2022-02-06 00:29:29 * @LastEditors: 牙叔 * @Description: * @FilePath: \autojs-test\main.js * @名人名言: 牙叔教程 简单易懂 * @bilibili: 牙叔教程 * @公众号: 牙叔教程 * @QQ群: 747748653 */ importClass(android.animation.ObjectAnimator); importClass(android.animation.AnimatorSet); importClass(java.io.BufferedInputStream); importClass(java.io.BufferedOutputStream); importClass(java.io.File); importClass(java.io.FileInputStream); importClass(java.io.FileNotFoundException); importClass(java.io.FileOutputStream); importClass(java.io.IOException); importClass(java.io.InputStream); importClass(java.io.OutputStream); let filePath = "/sdcard/MT2/apks/aaa.apk"; let 分割后的文件所在文件夹 = "/sdcard/aaa分割文件"; log("删除文件夹 = " + files.removeDir(分割后的文件所在文件夹)); files.ensureDir(分割后的文件所在文件夹); splitFile(filePath, 分割后的文件所在文件夹); let filePathList = getFilePathList(分割后的文件所在文件夹); log("filePathList ="); log(filePathList); merge(分割后的文件所在文件夹, filePathList); /* -------------------------------------------------------------------------- */ function getFilePathList(dest) { let filePathList = []; var dir = dest + "/"; log("dir = " + dir); filePathList = files.listDir(dir, function (name) { return name.indexOf("-yashu-") && files.isFile(files.join(dir, name)); }); if (filePathList.length === 0) { toastLog("分割的文件列表不存在"); exit(); } else { log("分割的文件列表存在"); } filePathList = filePathList.map((filePath) => { return files.join(dest, filePath); }); filePathList.sort(function (a, b) { return parseInt(a.split("-yashu-")[1]) - parseInt(b.split("-yashu-")[1]); }); filePathList = filePathList.map((filePath) => { return new File(files.join(filePath)); }); return filePathList; } function merge(dest, files) { log("files[0] = " + files[0]); let filename = files[0].getName(); log("filename1 = " + filename); filename = files[0].getName().substring(0, filename.lastIndexOf("-")).replace("-yashu", ""); log("filename2 = " + filename); let filePath = dest + File.separator + filename; log("filePath = " + filePath); let bos = new BufferedOutputStream(new FileOutputStream(filePath)); // bytes = new byte[1024 * 1024](); bytes = util.java.array("byte", 1024 * 1024); let len = -1; for (let i = 0; i < files.length; i++) { let bis = new BufferedInputStream(new FileInputStream(files[i])); while ((len = bis.read(bytes)) != -1) { bos.write(bytes, 0, len); } } log("合并完成"); } function splitFile(src, dest, mb) { files.create(dest + "/"); mb = mb || 1; let srcFile = new File(src); let countSize = srcFile.length(); let fileSize = 1024 * 1024 * mb; let num = 0; if (countSize % fileSize == 0) { num = countSize / fileSize; } else { num = countSize / fileSize + 1; } let InputStream = new FileInputStream(srcFile); let bis = new BufferedInputStream(InputStream); let bytes = util.java.array("byte", fileSize); let len = -1; for (let i = 0; i < num; i++) { let newFile = dest + File.separator + srcFile.getName() + "-yashu-" + i; let bos = new BufferedOutputStream(new FileOutputStream(newFile)); let count = 0; while ((len = bis.read(bytes)) != -1) { bos.write(bytes, 0, len); bos.flush(); count += len; if (count >= fileSize) { break; } } bos.close(); } bis.close(); InputStream.close(); log("分割完成"); }
环境
手机: Mi 11 Pro
Android版本: 12
Autojs版本: 9.1.2
名人名言
思路是最重要的, 其他的百度, bing, stackoverflow, github, 安卓文档, autojs文档, 最后才是群里问问
--- 牙叔教程
声明
部分内容来自网络
本教程仅用于学习, 禁止用于其他用途