ZipEntry路径名的文件分隔符? [英] File separators of Path name of ZipEntry?

查看:236
本文介绍了ZipEntry路径名的文件分隔符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ZIP条目存储条目的完整路径名,因为(我确定下一部分)ZIP存档未组织为目录。元数据包含有关文件应该如何存储的信息(内部目录)。

ZIP entries store the full path name of the entry because (I'm sure of the next part) the ZIP archive is not organized as directories. The metadata contains the info about how files are supposed to be stored (inside directories).

如果我在Windows中创建ZIP文件,当我在另一个操作系统中解压缩数据时,例如Mac OS X,文件结构保持与以前一样在Windows中。这是因为unzipper是为处理这个而设计的,还是因为ZIP中的文件分隔符是标准的?

If I create a ZIP file in Windows, when I unzip the data in another OS, e.g. Mac OS X, the file structure remains as it used to be in Windows. Is this because the unzipper is designed to handle this, or isit because the file separators inside the ZIP are standard?

我问这个是因为我试图找到ZIP文件中的条目,使用压缩文件的名称。但是我应该使用哪个文件分隔符使其在Windows以外的系统中工作?

I'm asking this because I'm trying to find an entry inside a ZIP file using the name of the zipped file. But which file separator should I use to make it work in systems other than Windows?

我正在使用Java,方法: .getName () ZipEntry 为我提供了使用Windows文件分隔符 \ 的路径。如果我使用java File.separator 分隔符使其在另一个操作系统上运行,这样就足够了吗?或者我是否必须尝试使用​​每个可能的分隔符找到我的文件?

I'm using Java, and the method: .getName() of the ZipEntry gives me the path using the Windows file separator \. Would it be enough if I use the java File.separator separator to make it work on another OS? Or will I have to try to find my file with each possible separator?

推荐答案

文件分隔符取决于创建zip文件的应用程序。某些应用程序使用系统文件分隔符,而有些应用程序使用文明正斜杠/。因此,如果您正在创建zip文件然后使用它,那么您只需使用正斜杠作为文件分隔符。如果zip文件是在其他地方创建的,那么您应该找出使用了哪个分隔符。我不知道一个简单的方法,但你可以使用一个粗暴的方法,并在你进步时检查两个分隔符类型。

The file separator is dependent on the application that creates the zip file. Some applications use the system file separator, whereas some use the "civilized" forward slash "/". So, if you are creating the zip file and then consuming it, then you can simply use a forward slash as file separator. If the zip file is created on somewhere else, then you should find out which separator was used. I don't know a simple way, but you can use a brute method and check out both separator types as you progress.

一些应用程序,尤其是自定义zip创建代码,可以在不同的zip条目上混合分隔符,所以不要忘记查看每个条目。

Some applications, especially custom zip creation codes, can mix the separators on different zip entries, so don't forget to check out each entry.

这篇关于ZipEntry路径名的文件分隔符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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