我正在尝试创建一个csv文件并压缩它。看起来这个异常的原因是大小(即csv中列名的字节大小计数)超过了8192字节。我想知道如何增加这个限制,是否可以或任何其他解决方案。请建议。
提前谢谢。
java.util.zip.ZipException: no current ZIP entry
at java.util.zip.ZipOutputStream.write(ZipOutputStream.java:326)
at sun.nio.cs.StreamEncoder.writeBytes(StreamEncoder.java:221)
at sun.nio.cs.StreamEncoder.implWrite(StreamEncoder.java:282)
at sun.nio.cs.StreamEncoder.write(StreamEncoder.java:125)
at sun.nio.cs.StreamEncoder.write(StreamEncoder.java:135)
at java.io.OutputStreamWriter.write(OutputStreamWriter.java:220)
at java.io.Writer.write(Writer.java:157)
at java.io.Writer.append(Writer.java:269)
at java.io.Writer.append(Writer.java:50)
at org.apache.commons.csv.CSVFormat.printWithQuotes(CSVFormat.java:1475)
at org.apache.commons.csv.CSVFormat.print(CSVFormat.java:1224)
at org.apache.commons.csv.CSVFormat.print(CSVFormat.java:1210)
at org.apache.commons.csv.CSVFormat.printRecord(CSVFormat.java:1322)
at org.apache.commons.csv.CSVPrinter.printRecord(CSVPrinter.java:271)
at org.apache.commons.csv.CSVPrinter.<init>(CSVPrinter.java:110)
at com.carrieriq.metriclog.business.transformer.csv.Test.main(Test.java:216)
测验JAVA
package com.carrieriq.metriclog.business.transformer.csv;
import org.apache.commons.csv.CSVFormat;
import org.apache.commons.csv.CSVPrinter;
import javax.servlet.ServletOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.zip.ZipOutputStream;
public class Test {
public static void main(String[] args) {
try
{
String [] csvHeaderElements = {
"onethree_onethreeFour0",
"onethree_onethreeFour1",
"onethree_onethreeFour2",
"onethree_onethreeFour3",
"onethree_onethreeFour4",
"onethree_onethreeFour5",
"onethree_onethreeFour6",
"onethree_onethreeFour7",
"onethree_onethreeFour8",
"onethree_onethreeFour9",
"onethree_onethreeFour10",
"onethree_onethreeFour11",
"onethree_onethreeFour12",
"onethree_onethreeFour13",
"onethree_onethreeFour14",
"onethree_onethreeFour15",
"onethree_onethreeFour16",
"onethree_onethreeFour17",
"onetwothree_onetwo0_onetwo_rec0_ack",
"onetwothree_onetwo0_onetwo_rec0_nack",
"onetwothree_onetwo0_onetwo_rec0_dtx",
"onetwothree_onetwo0_onetwo_rec1_ack",
"onetwothree_onetwo0_onetwo_rec1_nack",
"onetwothree_onetwo0_onetwo_rec1_dtx",
"onetwothree_onetwo0_onetwo_rec2_ack",
"onetwothree_onetwo0_onetwo_rec2_nack",
"onetwothree_onetwo0_onetwo_rec2_dtx",
"onetwothree_onetwo0_onetwo_rec3_ack",
"onetwothree_onetwo0_onetwo_rec3_nack",
"onetwothree_onetwo0_onetwo_rec3_dtx",
"onetwothree_onetwo0_onetwo_rec4_ack",
"onetwothree_onetwo0_onetwo_rec4_nack",
"onetwothree_onetwo0_onetwo_rec4_dtx",
"onetwothree_onetwo0_onetwo_rec5_ack",
"onetwothree_onetwo0_onetwo_rec5_nack",
"onetwothree_onetwo0_onetwo_rec5_dtx",
"onetwothree_onetwo0_onetwo_rec6_ack",
"onetwothree_onetwo0_onetwo_rec6_nack",
"onetwothree_onetwo0_onetwo_rec6_dtx",
"onetwothree_onetwo0_onetwo_rec7_ack",
"onetwothree_onetwo0_onetwo_rec7_nack",
"onetwothree_onetwo0_onetwo_rec7_dtx",
"onetwothree_onetwo0_onetwo_rec8_ack",
"onetwothree_onetwo0_onetwo_rec8_nack",
"onetwothree_onetwo0_onetwo_rec8_dtx",
"onetwothree_onetwo0_onetwo_rec9_ack",
"onetwothree_onetwo0_onetwo_rec9_nack",
"onetwothree_onetwo0_onetwo_rec9_dtx",
"onetwothree_onetwo0_onetwo_rec10_ack",
"onetwothree_onetwo0_onetwo_rec10_nack",
"onetwothree_onetwo0_onetwo_rec10_dtx",
"onetwothree_onetwo0_onetwo_rec11_ack",
"onetwothree_onetwo0_onetwo_rec11_nack",
"onetwothree_onetwo0_onetwo_rec11_dtx",
"onetwothree_onetwo0_onetwo_rec12_ack",
"onetwothree_onetwo0_onetwo_rec12_nack",
"onetwothree_onetwo0_onetwo_rec12_dtx",
"onetwothree_onetwo0_onetwo_rec13_ack",
"onetwothree_onetwo0_onetwo_rec13_nack",
"onetwothree_onetwo0_onetwo_rec13_dtx",
"onetwothree_onetwo0_onetwo_rec14_ack",
"onetwothree_onetwo0_onetwo_rec14_nack",
"onetwothree_onetwo0_onetwo_rec14_dtx",
"onetwothree_onetwo0_onetwo_rec15_ack",
"onetwothree_onetwo0_onetwo_rec15_nack",
"onetwothree_onetwo0_onetwo_rec15_dtx",
"onetwothreefour_onetwothreefour_rec0_onetwo0_onetwo_rec0_ack",
"onetwothreefour_onetwothreefour_rec0_onetwo0_onetwo_rec0_nack",
"onetwothreefour_onetwothreefour_rec0_onetwo0_onetwo_rec0_dtx",
"onetwothreefour_onetwothreefour_rec0_onetwo0_onetwo_rec1_ack",
"onetwothreefour_onetwothreefour_rec0_onetwo0_onetwo_rec1_nack",
"onetwothreefour_onetwothreefour_rec0_onetwo0_onetwo_rec1_dtx",
"onetwothreefour_onetwothreefour_rec0_onetwo0_onetwo_rec2_ack",
"onetwothreefour_onetwothreefour_rec0_onetwo0_onetwo_rec2_nack",
"onetwothreefour_onetwothreefour_rec0_onetwo0_onetwo_rec2_dtx",
"onetwothreefour_onetwothreefour_rec0_onetwo0_onetwo_rec3_ack",
"onetwothreefour_onetwothreefour_rec0_onetwo0_onetwo_rec3_nack",
"onetwothreefour_onetwothreefour_rec0_onetwo0_onetwo_rec3_dtx",
"onetwothreefour_onetwothreefour_rec0_onetwo0_onetwo_rec4_ack",
"onetwothreefour_onetwothreefour_rec0_onetwo0_onetwo_rec4_nack",
"onetwothreefour_onetwothreefour_rec0_onetwo0_onetwo_rec4_dtx",
"onetwothreefour_onetwothreefour_rec0_onetwo0_onetwo_rec5_ack",
"onetwothreefour_onetwothreefour_rec0_onetwo0_onetwo_rec5_nack",
"onetwothreefour_onetwothreefour_rec0_onetwo0_onetwo_rec5_dtx",
"onetwothreefour_onetwothreefour_rec0_onetwo0_onetwo_rec6_ack",
"onetwothreefour_onetwothreefour_rec0_onetwo0_onetwo_rec6_nack",
"onetwothreefour_onetwothreefour_rec0_onetwo0_onetwo_rec6_dtx",
"onetwothreefour_onetwothreefour_rec0_onetwo0_onetwo_rec7_ack",
"onetwothreefour_onetwothreefour_rec0_onetwo0_onetwo_rec7_nack",
"onetwothreefour_onetwothreefour_rec0_onetwo0_onetwo_rec7_dtx",
"onetwothreefour_onetwothreefour_rec0_onetwo0_onetwo_rec8_ack",
"onetwothreefour_onetwothreefour_rec0_onetwo0_onetwo_rec8_nack",
"onetwothreefour_onetwothreefour_rec0_onetwo0_onetwo_rec8_dtx",
"onetwothreefour_onetwothreefour_rec0_onetwo0_onetwo_rec9_ack",
"onetwothreefour_onetwothreefour_rec0_onetwo0_onetwo_rec9_nack",
"onetwothreefour_onetwothreefour_rec0_onetwo0_onetwo_rec9_dtx",
"onetwothreefour_onetwothreefour_rec0_onetwo0_onetwo_rec10_ack",
"onetwothreefour_onetwothreefour_rec0_onetwo0_onetwo_rec10_nack",
"onetwothreefour_onetwothreefour_rec0_onetwo0_onetwo_rec10_dtx",
"onetwothreefour_onetwothreefour_rec0_onetwo0_onetwo_rec11_ack",
"onetwothreefour_onetwothreefour_rec0_onetwo0_onetwo_rec11_nack",
"onetwothreefour_onetwothreefour_rec0_onetwo0_onetwo_rec11_dtx",
"onetwothreefour_onetwothreefour_rec0_onetwo0_onetwo_rec12_ack",
"onetwothreefour_onetwothreefour_rec0_onetwo0_onetwo_rec12_nack",
"onetwothreefour_onetwothreefour_rec0_onetwo0_onetwo_rec12_dtx",
"onetwothreefour_onetwothreefour_rec0_onetwo0_onetwo_rec13_ack",
"onetwothreefour_onetwothreefour_rec0_onetwo0_onetwo_rec13_nack",
"onetwothreefour_onetwothreefour_rec0_onetwo0_onetwo_rec13_dtx",
"onetwothreefour_onetwothreefour_rec0_onetwo0_onetwo_rec14_ack",
"onetwothreefour_onetwothreefour_rec0_onetwo0_onetwo_rec14_nack",
"onetwothreefour_onetwothreefour_rec0_onetwo0_onetwo_rec14_dtx",
"onetwothreefour_onetwothreefour_rec0_onetwo0_onetwo_rec15_ack",
"onetwothreefour_onetwothreefour_rec0_onetwo0_onetwo_rec15_nack",
"onetwothreefour_onetwothreefour_rec0_onetwo0_onetwo_rec15_dtx",
"onetwothreefour_onetwothreefour_rec1_onetwo0_onetwo_rec0_ack",
"onetwothreefour_onetwothreefour_rec1_onetwo0_onetwo_rec0_nack",
"onetwothreefour_onetwothreefour_rec1_onetwo0_onetwo_rec0_dtx",
"onetwothreefour_onetwothreefour_rec1_onetwo0_onetwo_rec1_ack",
"onetwothreefour_onetwothreefour_rec1_onetwo0_onetwo_rec1_nack",
"onetwothreefour_onetwothreefour_rec1_onetwo0_onetwo_rec1_dtx",
"onetwothreefour_onetwothreefour_rec1_onetwo0_onetwo_rec2_ack",
"onetwothreefour_onetwothreefour_rec1_onetwo0_onetwo_rec2_nack",
"onetwothreefour_onetwothreefour_rec1_onetwo0_onetwo_rec2_dtx",
"onetwothreefour_onetwothreefour_rec1_onetwo0_onetwo_rec3_ack",
"onetwothreefour_onetwothreefour_rec1_onetwo0_onetwo_rec3_nack",
"onetwothreefour_onetwothreefour_rec1_onetwo0_onetwo_rec3_dtx",
"onetwothreefour_onetwothreefour_rec1_onetwo0_onetwo_rec4_ack",
"onetwothreefour_onetwothreefour_rec1_onetwo0_onetwo_rec4_nack",
"onetwothreefour_onetwothreefour_rec1_onetwo0_onetwo_rec4_dtx",
"onetwothreefour_onetwothreefour_rec1_onetwo0_onetwo_rec5_ack",
"onetwothreefour_onetwothreefour_rec1_onetwo0_onetwo_rec5_nack",
"onetwothreefour_onetwothreefour_rec1_onetwo0_onetwo_rec5_dtx",
"onetwothreefour_onetwothreefour_rec1_onetwo0_onetwo_rec6_ack",
"onetwothreefour_onetwothreefour_rec1_onetwo0_onetwo_rec6_nack",
"onetwothreefour_onetwothreefour_rec1_onetwo0_onetwo_rec6_dtx",
"onetwothreefour_onetwothreefour_rec1_onetwo0_onetwo_rec7_ack",
"onetwothreefour_onetwothreefour_rec1_onetwo0_onetwo_rec7_nack",
"onetwothreefour_onetwothreefour_rec1_onetwo0_onetwo_rec7_dtx",
"onetwothreefour_onetwothreefour_rec1_onetwo0_onetwo_rec8_ack",
"onetwothreefour_onetwothreefour_rec1_onetwo0_onetwo_rec8_nack",
"onetwothreefour_onetwothreefour_rec1_onetwo0_onetwo_rec8_dtx",
"onetwothreefour_onetwothreefour_rec1_onetwo0_onetwo_rec9_ack",
"onetwothreefour_onetwothreefour_rec1_onetwo0_onetwo_rec9_nack",
"onetwothreefour_onetwothreefour_rec1_onetwo0_onetwo_rec9_dtx",
"onetwothreefour_onetwothreefour_rec1_onetwo0_onetwo_rec10_ack",
"onetwothreefour_onetwothreefour_rec1_onetwo0_onetwo_rec10_nack",
"onetwothreefour_onetwothreefour_rec1_onetwo0_onetwo_rec10_dtx",
"onetwothreefour_onetwothreefour_rec1_onetwo0_onetwo_rec11_ack",
"onetwothreefour_onetwothreefour_rec1_onetwo0_onetwo_rec11_nack",
"onetwothreefour_onetwothreefour_rec1_onetwo0_onetwo_rec11_dtx",
"onetwothreefour_onetwothreefour_rec1_onetwo0_onetwo_rec12_ack",
"onetwothreefour_onetwothreefour_rec1_onetwo0_onetwo_rec12_nack",
"onetwothreefour_onetwothreefour_rec1_onetwo0_onetwo_rec12_dtx",
"onetwothreefour_onetwothreefour_rec1_onetwo0_onetwo_rec13_ack",
"onetwothreefour_onetwothreefour_rec1_onetwo0_onetwo_rec13_nack",
"onetwothreefour_onetwothreefour_rec1_onetwo0_onetwo_rec13_dtx",
"onetwothreefour_onetwothreefour_rec1_onetwo0_onetwo_rec14_ack",
"onetwothreefour_onetwothreefour_rec1_onetwo0_onetwo_rec14_nack",
"onetwothreefour_onetwothreefour_rec1_onetwo0_onetwo_rec14_dtx",
"onetwothreefour_onetwothreefour_rec1_onetwo0_onetwo_rec15_ack",
"onetwothreefour_onetwothreefour_rec1_onetwo0_onetwo_rec15_nack",
"onetwothreefour_onetwothreefour_rec1_onetwo0_onetwo_rec15_dtx",
"onetwothreefour_onetwothreefour_rec2_onetwo0_onetwo_rec0_ack",
"onetwothreefour_onetwothreefour_rec2_onetwo0_onetwo_rec0_nack"
};
ServletOutputStream out = new ServletOutputStream() {
@Override
public void write(int b) throws IOException {
System.out.println(b);
}
};
int count = 0;
for(String str : csvHeaderElements) {
count += str.length();
}
System.out.println("size " + count);
System.out.println("size of array is " + csvHeaderElements.length);
ZipOutputStream zos = new ZipOutputStream(out);
CSVPrinter csvPrinter = new CSVPrinter(
new OutputStreamWriter(zos),
CSVFormat.EXCEL.withHeader(csvHeaderElements)
//CSVFormat.DEFAULT.withHeader(csvHeaderElements)
);
} catch (IOException e)
{
e.printStackTrace();
}
}
}
你不能仅仅通过复制CSV文件的内容来创建zip,你需要先创建一个zip条目。所以代码应该是这样的:
String[] csvHeaderElements = { // some headers separated with semicolon
};
try (ZipOutputStream zos = new ZipOutputStream(new FileOutputStream("C:/Users/TestUser/Downloads/test.zip"))) {
// create zip entry
ZipEntry entry = new ZipEntry("test.csv");
zos.putNextEntry(entry);
CSVPrinter csvPrinter = new CSVPrinter(new OutputStreamWriter(zos), CSVFormat.EXCEL.builder().setHeader(csvHeaderElements).build());
// some action with csvPrinter
// ...
// close entry
zos.closeEntry();
}
ZIP流需要一个条目,它将在ZIP内容中设置文件名。使用try with resources确保ZIP输出流正确关闭。本例定义了名为“somename.xyz”的条目中的内容:
try(ZipOutputStream zos = new ZipOutputStream(out)) {
zos.putNextEntry(new ZipEntry("somename.xyz"));
OutputStreamWriter wr = new OutputStreamWriter(zos);
CSVPrinter csvPrinter = new CSVPrinter(wr,
CSVFormat.EXCEL.withHeader(csvHeaderElements)
);
wr.flush();
}
或者,您可能对GZIP流感到困惑,因为GZIP流更容易设置,只需将ZipOutputStream
更改为GZIPOutputStream
:
try(GZIPOutputStream zos = new GZIPOutputStream(out)) {
OutputStreamWriter wr = new OutputStreamWriter(zos);
CSVPrinter csvPrinter = new CSVPrinter(wr,
CSVFormat.EXCEL.withHeader(csvHeaderElements)
);
wr.flush();
}
我正在用jnlp启动java web start应用程序。jnlp是使用jsp动态生成的。我已经设置了jnlp。在jnlp文件中,packEnabled为true。所有的罐子都重新包装、签名,并用java的pack200包装。使用下面的ant脚本。 在Web启动应用程序启动其给予上面的错误.请建议如何解决这个错误.而当我尝试查看*.pack.gz文件与WINRAR,我可以看到只有一个文件与. pa
错误:任务“:DrivermaticsApp:PackageAllDebugClassesFormultiDex”执行失败。 zipException:重复条目:com/flurry/sdk/jv$a.class 请帮忙... 这是我的建筑。格雷德尔:-
它会发生此错误。 该应用程序构建成功,但当我获得build apk时,android studio会显示此消息 这是我的gradle 我认为外部库有Commons-io-1.3.2.jarCommons-io-2.4.jar都有CopyUtils.class 无论如何,它无法构建apk并显示该消息。 请任何人帮帮我
我从服务器收到一个zip文件,它必须被处理。我可以手动解压缩它。所以我相信zip文件没有被破坏。 下面的代码从Zip文件中读取文件而不解压它。 注意:我从服务器收到的zip文件大小为5MB。但是一旦我解压缩并压缩回来,新的zip文件大小变成了8MB。 增加:
我不知道为什么我会得到这个错误。任何帮助都是值得赞赏的 zipException:重复条目:com/google/zxing/barcodeformat.class buildscript{repositories{mavenCentral()}dependencies{classpath“com.android.tools.build:Gradle:1.3.0”}}allprojects{rep
早上好, 当我从Hibernate3升级到4时,出现了“臭名昭著的”当前会话错误。我搜索了一下,似乎一切都安排妥当了。我需要一些洞察力:) 这是我的配置:Spring3.2Hibernate4.1.9 数据源上下文: 业务背景: 我的服务层: 最后,DAO实现: 这里是stackTrace: 谢谢你的帮助! 编辑: 好的,我清理了配置文件,现在: 对于DAO: 对于业务层: 并从DAO中删除@Tr