使用 JDK 5 api 从 zip 文件中提取时保持文件权限 [英] Maintain file permissions when extracting from a zip file using JDK 5 api

查看:16
本文介绍了使用 JDK 5 api 从 zip 文件中提取时保持文件权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 java.util.Zip 和 java.util.ZipEntry 成功地将 zip 文件的内容附加到磁盘.我想在 *nix 文件系统上提取时保持文件权限集.

谁能指出我执行此操作的正确"方法吗?

解决方案

本质上,您无法在 Zip/Jar 文件中存储 (unix) 文件权限,因此在提取 jar 时无法保留它们(它们已丢失)当 jar 开始创建时).请参阅此问题:创建 jar 文件 - 保留文件权限>

如果您需要保留存档中的文件权限并在提取时恢复,则需要考虑替代 .tar 或 .tar.gz/.tar.bz2 格式,大多数 Java 构建工具(Ant、Gradle、Maven...)

I am using java.util.Zip and java.util.ZipEntry to successfully extra a zip file's contents to disk. I would like to maintain the file permissions set when extracting on a *nix file-system.

Can anyone point me to the "correct" way to do this?

解决方案

Essentially, you can't STORE (unix) file permissions in Zip/Jar files, so you can't preserve them when extracting your jar (they were lost when the jar was created to begin with). See this question: creating a jar file - preserving file permissions

If you need the file permissions preserved in the archive and restored when extracting, you need to consider the alternative .tar or .tar.gz / .tar.bz2 format, which is also natively supported by most Java build tools (Ant, Gradle, Maven...)

这篇关于使用 JDK 5 api 从 zip 文件中提取时保持文件权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆