File f1 = new

File("C:/boot.ini");

File f2 = new File("C:/NTDETECT.COM");

final ByteArrayOutputStream baos =

new ByteArrayOutputStream() ;

//changed @ 2009年7月21日8:37:41

//ArchiveOutputStream ostemp = new

ArchiveStreamFactory().createArchiveOutputStream("zip", baos);

ZipArchiveOutputStream

ostemp = new ZipArchiveOutputStream(baos);

ostemp.setEncoding("GBK");

ostemp.putArchiveEntry(new

ZipArchiveEntry(f1.getName()));

IOUtils.copy(new

FileInputStream(f1), ostemp);

ostemp.closeArchiveEntry();

ostemp.putArchiveEntry(new

ZipArchiveEntry(f2.getName()));

IOUtils.copy(new

FileInputStream(f2), ostemp);

ostemp.closeArchiveEntry();

ostemp.finish();

ostemp.close();

final OutputStream out = new

FileOutputStream("c:/test.zip");

ArchiveOutputStream os = new

ArchiveStreamFactory().createArchiveOutputStream("zip", out);

os.putArchiveEntry(new

ZipArchiveEntry("打包.zip"));

baos.writeTo(os);

os.closeArchiveEntry();

baos.close();

os.finish();

os.close();

Logo

汇聚全球AI编程工具,助力开发者即刻编程。

更多推荐