使用 ZipOutputStream 的 Zip 文件中的子目录

发布于 2024-12-19 14:31:29 字数 395 浏览 5 评论 0原文

我正在使用此处描述的技术创建一个 zip 文件:

http://info.michael-simons.eu/2008/01/21/using-rubyzip-to-create-zip-files-on-the-fly/

客户已询问我在此 zip 文件中包含子目录。我搜索了 ZipOutputStream 文档,但我看不到包含目录的方法。有没有办法用 ZipOutputStream 做到这一点?我应该使用与 ZipOutputStream 不同的类吗?

此外,我正在压缩的文件不在本地文件系统上,而是存储在云服务中。

I am creating a zip file using the technique described here:

http://info.michael-simons.eu/2008/01/21/using-rubyzip-to-create-zip-files-on-the-fly/

The client has asked that I include subdirectories in this zip file. I have searched the ZipOutputStream documentation but I see no way to include directories. Is there a way I can do this with ZipOutputStream? Should I be using a different class than ZipOutputStream?

Also, the files that I am zipping are not on the local filesystem, but are stored in a cloud service.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一个人的旅程 2024-12-26 14:31:29

找到了答案,我想我会把它放在这里以便搜索引擎找到。

不管怎样,我发布的链接

zos.put_next_entry("some-funny-name.jpg")

用于将文件添加到 zip 文件中。事实证明,该字符串参数不仅仅是一个文件名,它也可以是一个路径!因此,使用

zos.put_next_entry("some-random-folder/some-funny-name.jpg")

Will 会使您的 zip 文件包含一个名为“some-random-folder”的文件夹,以及一个名为“some-funny-name.jpg”的文件。

Figured out the answer, thought I would put it here for search engines to find.

Anyway, the link I posted used

zos.put_next_entry("some-funny-name.jpg")

to add files to the zip file. Turns out, that string parameter isn't just a filename, it can be a path as well! So using

zos.put_next_entry("some-random-folder/some-funny-name.jpg")

Will make your zip file contain a folder called 'some-random-folder', with a file called 'some-funny-name.jpg'.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文