本文由 发布,转载请注明出处,如有问题请联系我们! 发布时间: 2021-08-01java解压zip文件为空-java解压各种类型的文件
加载中我已经讲过怎样根据JAVA把JAR制成自缓解压力的exe文件。如今,要求收到了:当客户免费下载exe时,她们会全自动在exe文件中加上或遮盖某一文档。
思索:

2.从exe文件中,寻找config.txt末尾的部位.
3.将exe文件拆卸成2个临时文件夹:sfx config.txt文件和z7.7z压缩文件文档。
4.启用SevenZFile,再加上正中间的覆盖文件,产生一个新的压缩包,newz7.7z压缩文件。
5.将sfx config.txt文件和newz7.7z压缩文件合拼成exe初始解压缩文件。
编码如下所示:
在其中:d:\ test \ 7z self-extracting.exe是一个自缓解压力的exe文件。
/** * 查找文件中的config.txt末尾部位 * * @throws IOException */@Testpublic void getConfigEndPosTest() throws IOException {final File exeFile = new File("d:\test\7z自缓解压力.exe");final byte[] configEnd= ";!@InstallEnd@!".getBytes("ISO-8859-1");final BufferedInputStream exeBis = new BufferedInputStream(new FileInputStream(exeFile));// sfx假设超过124928exeBis.skip(124928);int b;long pos = 124928;int macth = 0;while ((b = exeBis.read()) != -1) {pos ;if (configEnd[macth] == b) {macth ;} else {macth = 0;}if (macth == 15) {System.out.print(pos);break;}}exeBis.close();}/** * 自压缩包拆分为: sfx config, 7z2个临时文件夹 * * @throws IOException */@Testpublic void splitFileTest() throws IOException {final File exeFile = new File("d:\test\7z自缓解压力.exe");final FileInputStream exeIn = new FileInputStream(exeFile);final File sfxFile = new File("d:\test\sfx.tmp");sfxFile.createNewFile();final FileOutputStream sfxOs = new FileOutputStream(sfxFile);// 125070 第一步求取的posbyte[] buffer = new byte[125070];int length;length = exeIn.read(buffer);sfxOs.write(buffer, 0, length);sfxOs.close();final File z7File = new File("d:\test\z7.7z");z7File.createNewFile();final FileOutputStream z7Os = new FileOutputStream(z7File);while ((length = exeIn.read(buffer)) > 0) {z7Os.write(buffer, 0, length);}z7Os.close();exeIn.close();}/** * 加上或遮盖的文档到7z * * @throws IOException */@Testpublic void writeFileTo7z() throws IOException { //略,7z文档解决}/** * sfx config 新的7z文档成exe. * @throws IOException */@Testpublic void mergeFile() throws IOException {//略, 参照前一篇的《JAVA JAR制作可自运行的EXE包》}