public static void main(String[] args) {
System.out.println(readZipFileName("D:/123.zip"));
}
//读取zip文件内的文件,返回文件名称列表
public static List<Map<String, Object>> readZipFileName(String path){
List<Map<String, Object>> list = new ArrayList<>();
try {
// windows环境下,默认字符集为GBK,ZipFile默认使用UTF-8字符集,当文件名存在中文时,处理时就会报错
ZipFile zipFile = new ZipFile(path, Charset.forName("GBK"));
Enumeration<? extends ZipEntry> entries = zipFile.entries();
while (entries.hasMoreElements()) {
ZipEntry entry = entries.nextElement();
// System.out.println(entry.getName());
// System.out.println(entry.getSize());
Map<String, Object> map = new HashMap<>();
map.put("name",entry.getName());
map.put("size",entry.getSize());
list.add(map);
}
} catch (IOException e) {
e.printStackTrace();
}
return list;
}