简体   繁体   English

如何在java中的zip文件中访问文件和文件夹列表?

[英]How to acess list of files and folders in a zip file in java?

I am trying to retrieve a list of folders and files that are in a zipped file but it returns null 我正在尝试检索压缩文件中的文件夹和文件列表,但它返回null

File zipDir = new File(strFilePath+".zip");

String[] dirList = zipDir.list();

Can anyone please tell me what mistake I am making here or is there any other alternative? 任何人都可以告诉我我在这里犯了什么错误,或者还有其他选择吗?

You need to use the ZipFile class, eg like 您需要使用ZipFile类,例如

ZipFile zipFile = new ZipFile(strFilePath + ".zip");
Enumeration<? extends ZipEntry> entries = zipFile.entries();
while(entries.hasMoreElements()) {
    ZipEntry entry = entries.nextElement();
    System.err.println(entry.getName());
}

See also List Contents Of Zip File Example . 另请参阅Zip文件示例的列表内容

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM