我有一个 InputStream 对象,它实际上是一个 zip 文件。我想把它改回 zip 文件并保存。我正在使用 DWR 的 FileTransfer 类对象从客户端接收上传的数据。
FileTransfer有 3 个方法,getInputStream()就是其中之一。它从 FileTransfer 对象返回 InputStream。
在我的例子中,fileTransfer 对象包含 zip 文件以及 InputStream 对象。我已经完成了,在谷歌中进行了很多搜索。但我找不到一个例子来说明 InputStream 到 zip 的转换。
更新
String zipName = file.getName();
String zipType = file.getMimeType();
InputStream zipStream = file.getInputStream();
ZipInputStream zis = new ZipInputStream(zipStream);
System.out.println("File Name: "+zipName+"\n"+"File Type: "+zipType);
int c;
File f2 = new File(DATA_STORE_LOC+dat+".zip");
path.setPath2(DATA_STORE_LOC+dat+".zip");
FileOutputStream fos = new FileOutputStream(f2);
ZipOutputStream zos = new ZipOutputStream(fos);
c = zis.read();
System.out.println(c);
while ((c = zis.read(BUFFER)) != -1) {
zos.write(BUFFER, 0, c);
}
zos.close();
zis.close();
我尝试了这段代码,想到了一个典型的文件复制程序。我知道这是假的,刚试过。它给了我java.util.zip.ZipException: ZIP file must have at least one entry
。
任何建议都会非常感激!!!!!!!