获取zip文件里的第一目录名;
测试用例:
@Test
public void nsyc() {
String imageName = "IMAGE_129201.zip";
String ossDownloadpath = "D:/File/";
ZipUtil. getZipList(ossDownloadpath, imageName);
}
public class ZipUtil {
private String fileName;
public String getFileName() {
return fileName;
}
public void setFileName(String fileName) {
this.fileName = fileName;
}
/**获取zip目录*/
public static List<ZipUtil > getZipList(String ossDownloadpath, String imageName){
String zipPath = ossDownloadpath+imageName;
try {
ZipFile zipFile = new ZipFile(zipPath);
zipFile.setFileNameCharset("UTF-8");//设置编码格式
List<ZipUtil > fileHeaders= zipFile.getFileHeaders();
String obvc = JSON.toJSONString(fileHeaders);
List<ZipUtil > zipList = JSONObject.parseArray(obvc, ZipUtil .class);
return zipList;
}catch (ZipException e){
e.printStackTrace();
return null;
}
}
}