java - 设置仅流式传输的 zip 文件的文件名
问题描述
我目前正在创建一个 zip 文件并用各种 json 文件和图像填充它。所有这些都应该只在内存中运行,而不是在硬盘上。因此,到目前为止,我有以下构造:
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ZipOutputStream zip = null;
String FILE_NAME = "file.zip";
try {
zip = new ZipOutputStream(baos);
//now the critical part where the name of the file should be set
ZipEntry entry = new ZipEntry(FILE_NAME);
zip.putNextEntry(entry);
byte[] data = FILE_NAME.getBytes();
zip.write(data, 0, data.length);
zip.closeEntry();
//end of critical part and filling the rest of the zip
//...
//
}finally{
IOUtils.closeQuietly(zip);
byte[] byteFile = baos.toByteArray();
IOUtils.closeQuietly(baos);}
问题是 zip 文件称为 file.zip,但也包含 file.zip 本身。如何从 ZipOutputStream 中命名我的 Zip 文件,而不用打包到同名的这个文件中?不幸的是,我只在这里找到了这个解决方案。
解决方案
推荐阅读
- java - Wiremock 服务器无法将录音存储在指定目录中
- sql - Postgres重叠日期查询 - 查看两个日期作为一个范围是否重叠一个月
- python - 如何获得满足特定条件的 Dataframe 的一部分?
- fortran - Fortran 中的浮点运算
- wso2 - 两个网关工作人员可以将节流数据发布到一个流量管理器节点吗
- android - 无法将 Firebase 添加到 LibGDX 项目
- azure - 当 Windows 服务停止时,如何在 OMS 中创建警报?
- java - svnant 更新单个文件并跳过错误
- php - 如何在以键值为基础的多维数组中加入信息?
- c# - FolderBrowserDialog 添加自定义根名称