日期:2014-05-20 浏览次数:20951 次
ByteArrayOutputStream baos = new ByteArrayOutputStream();//字符串输出流
int len = 0;
while ((len = bin.read(buf)) != -1) {
baos.write(buf, 0, len);
}
ZipOutputStream zipOut = new ZipOutputStream(baos); //你这里的baos对象已经write完了,这里没了。
zipOut.putNextEntry(new ZipEntry("b.txt"));
------解决方案--------------------
try {
// Create the ZIP file
ZipOutputStream out = new ZipOutputStream(new ByteArrayOutputStream("aa").getBytes());
// Compress the files
FileInputStream in = new FileInputStream("aaaaaaaaaaa");
// Add ZIP entry to output stream.
out.putNextEntry(new ZipEntry("b.txt"));
// Transfer bytes from the file to the ZIP file
int len;
while ( (len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
// Complete the entry
out.closeEntry();
in.close();
// Complete the ZIP file
out.close();
}
catch (IOException e) {
e.printStackTrace();
}
这样。。。我没有测试。。你可以试试