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

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

问题描述

我正在使用java.util.Zip和java.util.ZipEntry成功地将zip文件的内容添加到磁盘。我想在* nix文件系统上解压缩时保持文件权限设置。

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?

推荐答案

基本上,你不能在Zip / Jar文件中存储(unix)文件权限,所以你不能保留它们提取你的jar时(它们在创建jar时就丢​​失了)。请参阅此问题:创建jar文件 - 保留文件权限

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

如果您需要保存在存档中的文件权限并在解压缩时恢复,则需要考虑替代.tar或.tar.gz / .tar.bz2格式,这是大多数Java构建工具(Ant,Gradle,Maven ......)本身也支持

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天全站免登陆