OutputStream out = new FileOutputStream(zipFilePath);
BufferedOutputStream bos = new BufferedOutputStream(out);
ZipOutputStream zos = new ZipOutputStream(bos);
// 解决中文文件名乱码
zos.setEncoding(UTF8);
File file = new File(sourceFolder+"/1/description.xml");
FileInputStream is = new FileInputStream(file);
BufferedInputStream bis = new BufferedInputStream(is);
byte[] cache = new byte[CACHE_SIZE];
zos.putNextEntry(new ZipEntry("1/"));//会在压缩文件中建立名字为1的文件夹
zos.putNextEntry(new ZipEntry("2/"));//会在压缩文件中建立名字为2的文件夹
zos.putNextEntry(new ZipEntry("1/description.xml"));//会在压缩文件中建立名字为1的文件夹中建立description.xml文件
int nRead = 0;
while ((nRead = bis.read(cache, 0, CACHE_SIZE)) != -1) {
zos.write(cache, 0, nRead);
}
bis.close();
is.close();
// zipFile(file, basePath, zos);
zos.closeEntry();
zos.close();
bos.close();
out.close();
ZipOutputStream压缩包用法
最新推荐文章于 2024-04-27 19:11:57 发布