我在Java中使用GZip时遇到问题。目前我使用gzip文件。一个gzip压缩文件中的一个文件。如果我手动解压他们,然后解析他们一切正常。但我想用Java和GZipInputStream自动执行此操作,但它不起作用。 我需要在最后有DataInputStream。我的代码是:Java将GzipInputStream转换为DataInputStream
byte[] bytesArray = Files.readAllBytes(baseFile.toPath());
try {
reader = new DataInputStream(new GZIPInputStream(new ByteArrayInputStream(bytesArray)));
System.out.println("gzip");
} catch (ZipException notZip) {
reader = new DataInputStream(new ByteArrayInputStream(bytesArray));
System.out.println("no gzip");
}
我也尝试新的GZIPInputStream(新的FileInputStream(baseFile)); 结果是一样的。由于输出,我看到Gzip流创建无一例外,但后来我从DataInputStream无效的数据。 请帮助:)
无效的数据,比如什么呢?当有效数据应该是什么?写的如何? – EJP
对不起:如果我使用原始文件或它的gzip版本,reader.readByte()会提供不同的结果。 – kapodes