/**
* 多个字符串直接做成文件打包返回字节数组,不需要写出
* @param dataMap key为文件名,value为文件内容的byte形势
* @return
* @throws IOException
*/
public static byte[] zip(Map<String, byte[]> dataMap) throws IOException {
byte[] b = null;
if(dataMap==null || dataMap.size() <= 0){
return b;
}
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ZipOutputStream zip = new ZipOutputStream(bos);
Set<String> key = dataMap.keySet();
for (Iterator<String> it = key.iterator(); it.hasNext();) {
String fileName = (String) it.next();
byte[] data = dataMap.get(fileName);
ZipEntry entry = new ZipEntry(fileName);
entry.setSize(data.length);
zip.putNextEntry(entry);
zip.write(data);
zip.closeEntry();
}
zip.close();
b = bos.toByteArray();
bos.close();
return b;
}
java zip
最新推荐文章于 2023-03-23 20:37:45 发布