gpt4 book ai didi

java - ZipEntry 脚本压缩目录,15 个文件中有 14 个为空

转载 作者:行者123 更新时间:2023-12-02 01:33:42 25 4
gpt4 key购买 nike

我修改了 ZipEntry 脚本来压缩 15 个 Excel 文件。现在我不是开发人员,所以我没有使用循环,基本上一遍又一遍地重复变量,所以代码很丑陋而且效率低下。除此之外,我只能使用 7-Zip 打开 zip,里面是一个目录。该目录中有 15 个 .xlsx 文件。 15 个文件中有 14 个是空白的...只有最后一个不是。

问题:

1) .zip 内的目录 - 如何删除它并让它直接压缩 15 个文件?

2) 15 个文件中的前 14 个是空白/0 KB。这是什么原因造成的?

这是代码:

var file_name_xlsx1 = getSystemDefault("RES_REPORTS_DIR")'EBAResolution_xxxxx_' + 'Z_01_00'+ '_' + DATE_STRING + '.xlsx';
var file_name_xlsx2 = getSystemDefault("RES_REPORTS_DIR")'EBAResolution_xxxxx_' + 'Z_02_00'+ '_' + DATE_STRING + '.xlsx';
var file_name_xlsx3 = getSystemDefault("RES_REPORTS_DIR")'EBAResolution_xxxxx_' + 'Z_03_00'+ '_' + DATE_STRING + '.xlsx';
var file_name_xlsx4 = getSystemDefault("RES_REPORTS_DIR")'EBAResolution_xxxxx_' + 'Z_04_00'+ '_' + DATE_STRING + '.xlsx';
var file_name_xlsx5 = getSystemDefault("RES_REPORTS_DIR")'EBAResolution_xxxxx_' + 'Z_05_01'+ '_' + DATE_STRING + '.xlsx';
var file_name_xlsx6 = getSystemDefault("RES_REPORTS_DIR")'EBAResolution_xxxxx_' + 'Z_05_02'+ '_' + DATE_STRING + '.xlsx';
var file_name_xlsx7 = getSystemDefault("RES_REPORTS_DIR")'EBAResolution_xxxxx_' + 'Z_06_00'+ '_' + DATE_STRING + '.xlsx';
var file_name_xlsx8 = getSystemDefault("RES_REPORTS_DIR")'EBAResolution_xxxxx_' + 'Z_07_01'+ '_' + DATE_STRING + '.xlsx';
var file_name_xlsx9 = getSystemDefault("RES_REPORTS_DIR")'EBAResolution_xxxxx_' + 'Z_07_02'+ '_' + DATE_STRING + '.xlsx';
var file_name_xlsx10 = getSystemDefault("RES_REPORTS_DIR")'EBAResolution_xxxxx_' + 'Z_07_03'+ '_' + DATE_STRING + '.xlsx';
var file_name_xlsx11 = getSystemDefault("RES_REPORTS_DIR")'EBAResolution_xxxxx_' + 'Z_07_04'+ '_' + DATE_STRING + '.xlsx';
var file_name_xlsx12 = getSystemDefault("RES_REPORTS_DIR")'EBAResolution_xxxxx_' + 'Z_08_00'+ '_' + DATE_STRING + '.xlsx';
var file_name_xlsx13 = getSystemDefault("RES_REPORTS_DIR")'EBAResolution_xxxxx_' + 'Z_09_00'+ '_' + DATE_STRING + '.xlsx';
var file_name_xlsx14 = getSystemDefault("RES_REPORTS_DIR")'EBAResolution_xxxxx_' + 'Z_10_01'+ '_' + DATE_STRING + '.xlsx';
var file_name_xlsx15 = getSystemDefault("RES_REPORTS_DIR")'EBAResolution_xxxxx_' + 'Z_10_02'+ '_' + DATE_STRING + '.xlsx';
var file_name_zip = getSystemDefault("RES_REPORTS_DIR")'EBAResolution_xxxxx' + '_' + DATE_STRING + '.zip';

var fileOS = new("java.io.FileOutputStream", file_name_zip);
var zipOS = new("java.util.zip.ZipOutputStream", fileOS);
zipOS.setLevel(9);
var zipEntry1 = new("java.util.zip.ZipEntry",file_name_xlsx1 );
zipOS.putNextEntry(zipEntry1);
var zipEntry2 = new("java.util.zip.ZipEntry",file_name_xlsx2 );
zipOS.putNextEntry(zipEntry2);
var zipEntry3 = new("java.util.zip.ZipEntry",file_name_xlsx3 );
zipOS.putNextEntry(zipEntry3);
var zipEntry4 = new("java.util.zip.ZipEntry",file_name_xlsx4 );
zipOS.putNextEntry(zipEntry4);
var zipEntry5 = new("java.util.zip.ZipEntry",file_name_xlsx5 );
zipOS.putNextEntry(zipEntry5);
var zipEntry6 = new("java.util.zip.ZipEntry",file_name_xlsx6 );
zipOS.putNextEntry(zipEntry6);
var zipEntry7 = new("java.util.zip.ZipEntry",file_name_xlsx7 );
zipOS.putNextEntry(zipEntry7);
var zipEntry8 = new("java.util.zip.ZipEntry",file_name_xlsx8 );
zipOS.putNextEntry(zipEntry8);
var zipEntry9 = new("java.util.zip.ZipEntry",file_name_xlsx9 );
zipOS.putNextEntry(zipEntry9);
var zipEntry10 = new("java.util.zip.ZipEntry",file_name_xlsx10 );
zipOS.putNextEntry(zipEntry10);
var zipEntry11 = new("java.util.zip.ZipEntry",file_name_xlsx11 );
zipOS.putNextEntry(zipEntry11);
var zipEntry12 = new("java.util.zip.ZipEntry",file_name_xlsx12 );
zipOS.putNextEntry(zipEntry12);
var zipEntry13 = new("java.util.zip.ZipEntry",file_name_xlsx13 );
zipOS.putNextEntry(zipEntry13);
var zipEntry14 = new("java.util.zip.ZipEntry",file_name_xlsx14 );
zipOS.putNextEntry(zipEntry14);
var zipEntry15 = new("java.util.zip.ZipEntry",file_name_xlsx15 );
zipOS.putNextEntry(zipEntry15);
var fileIS1 = new("java.io.FileInputStream", file_name_xlsx1);
var fileIS2 = new("java.io.FileInputStream", file_name_xlsx2);
var fileIS3 = new("java.io.FileInputStream", file_name_xlsx3);
var fileIS4 = new("java.io.FileInputStream", file_name_xlsx4);
var fileIS5 = new("java.io.FileInputStream", file_name_xlsx5);
var fileIS6 = new("java.io.FileInputStream", file_name_xlsx6);
var fileIS7 = new("java.io.FileInputStream", file_name_xlsx7);
var fileIS8 = new("java.io.FileInputStream", file_name_xlsx8);
var fileIS9 = new("java.io.FileInputStream", file_name_xlsx9);
var fileIS10 = new("java.io.FileInputStream", file_name_xlsx10);
var fileIS11 = new("java.io.FileInputStream", file_name_xlsx11);
var fileIS12 = new("java.io.FileInputStream", file_name_xlsx12);
var fileIS13 = new("java.io.FileInputStream", file_name_xlsx13);
var fileIS14 = new("java.io.FileInputStream", file_name_xlsx14);
var fileIS15 = new("java.io.FileInputStream", file_name_xlsx15);
var byteArray1 = class("axiomsl.util.basic.GenericClassUtils").readFileIntoByteArray(fileIS1, true);
var byteArray2 = class("axiomsl.util.basic.GenericClassUtils").readFileIntoByteArray(fileIS2, true);
var byteArray3 = class("axiomsl.util.basic.GenericClassUtils").readFileIntoByteArray(fileIS3, true);
var byteArray4 = class("axiomsl.util.basic.GenericClassUtils").readFileIntoByteArray(fileIS4, true);
var byteArray5 = class("axiomsl.util.basic.GenericClassUtils").readFileIntoByteArray(fileIS5, true);
var byteArray6 = class("axiomsl.util.basic.GenericClassUtils").readFileIntoByteArray(fileIS6, true);
var byteArray7 = class("axiomsl.util.basic.GenericClassUtils").readFileIntoByteArray(fileIS7, true);
var byteArray8 = class("axiomsl.util.basic.GenericClassUtils").readFileIntoByteArray(fileIS8, true);
var byteArray9 = class("axiomsl.util.basic.GenericClassUtils").readFileIntoByteArray(fileIS9, true);
var byteArray10 = class("axiomsl.util.basic.GenericClassUtils").readFileIntoByteArray(fileIS10, true);
var byteArray11 = class("axiomsl.util.basic.GenericClassUtils").readFileIntoByteArray(fileIS11, true);
var byteArray12 = class("axiomsl.util.basic.GenericClassUtils").readFileIntoByteArray(fileIS12, true);
var byteArray13 = class("axiomsl.util.basic.GenericClassUtils").readFileIntoByteArray(fileIS13, true);
var byteArray14 = class("axiomsl.util.basic.GenericClassUtils").readFileIntoByteArray(fileIS14, true);
var byteArray15 = class("axiomsl.util.basic.GenericClassUtils").readFileIntoByteArray(fileIS15, true);
zipOS.write(byteArray1, 0, byteArray1.size());
fileIS1.close();
zipOS.write(byteArray2, 0, byteArray2.size());
fileIS2.close();
zipOS.write(byteArray3, 0, byteArray3.size());
fileIS3.close();
zipOS.write(byteArray4, 0, byteArray4.size());
fileIS4.close();
zipOS.write(byteArray5, 0, byteArray5.size());
fileIS5.close();
zipOS.write(byteArray6, 0, byteArray6.size());
fileIS6.close();
zipOS.write(byteArray7, 0, byteArray7.size());
fileIS7.close();
zipOS.write(byteArray8, 0, byteArray8.size());
fileIS8.close();
zipOS.write(byteArray9, 0, byteArray9.size());
fileIS9.close();
zipOS.write(byteArray10, 0, byteArray10.size());
fileIS10.close();
zipOS.write(byteArray11, 0, byteArray11.size());
fileIS11.close();
zipOS.write(byteArray12, 0, byteArray12.size());
fileIS12.close();
zipOS.write(byteArray13, 0, byteArray13.size());
fileIS13.close();
zipOS.write(byteArray14, 0, byteArray14.size());
fileIS14.close();
zipOS.write(byteArray15, 0, byteArray15.size());
fileIS15.close();
zipOS.closeEntry();
zipOS.close();

'getSystemDefault("") 是一个特定于应用程序的函数,用于检索文件所在的应用程序服务器上的路径。正是该路径最终出现在生成的 .zip 中,导致 Windows 资源管理器使其无效。任何帮助将不胜感激。

最佳答案

您必须输入第一个条目,然后是第一个文件的内容,第二个条目,第二个文件内容,依此类推...

var zipEntry1 = new("java.util.zip.ZipEntry",file_name_xlsx1 );
zipOS.putNextEntry(zipEntry1);
var fileIS1 = new("java.io.FileInputStream", file_name_xlsx1);
var byteArray1 = class("axiomsl.util.basic.GenericClassUtils").readFileIntoByteArray(fileIS1, true);
zipOS.write(byteArray1, 0, byteArray1.size());
fileIS1.close();

var zipEntry2 = new("java.util.zip.ZipEntry",file_name_xlsx2 );
zipOS.putNextEntry(zipEntry2);
var fileIS2 = new("java.io.FileInputStream", file_name_xlsx2);
var byteArray2 = class("axiomsl.util.basic.GenericClassUtils").readFileIntoByteArray(fileIS2, true);
zipOS.write(byteArray2, 0, byteArray2.size());
fileIS2.close();
...

等等...

关于java - ZipEntry 脚本压缩目录,15 个文件中有 14 个为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55574808/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com