java.util.zip.ZipException: error in opening zip file
来源:互联网 发布:hit韩服数据 编辑:程序博客网 时间:2024/05/12 17:48
public class TestZipFile {
public static void main(String[] args) {
String filePath = "d:\\abc.zip";
File file = new File(filePath);
try {
//构造方法ZipFile(File file)或ZipFile(String filePath)
//打开ZIP文件进行阅读;
ZipFile zipFile = new ZipFile(file);
//返回 ZIP 文件条目的枚举
Enumeration entryEnum = zipFile.entries();
while (entryEnum.hasMoreElements()){
//hasMoreElements():测试此枚举是否包含更多的元素
//nextElement():如果此枚举对象至少还有一个可提供的元素,则返回此枚举的下一个元素。
//ZipEntry:此类用于表示 ZIP 文件条目
ZipEntry zipEntry = (ZipEntry)entryEnum.nextElement();
if(zipEntry.isDirectory()){
System.out.println("这是一个目录.......");
}else{
//getSize():返回条目数据的未压缩大小;如果未知,则返回 -1。
System.out.println(zipEntry.getSize());
}
}
} catch (ZipException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
String filePath = "d:\\abc.zip";
File file = new File(filePath);
try {
//构造方法ZipFile(File file)或ZipFile(String filePath)
//打开ZIP文件进行阅读;
ZipFile zipFile = new ZipFile(file);
//返回 ZIP 文件条目的枚举
Enumeration entryEnum = zipFile.entries();
while (entryEnum.hasMoreElements()){
//hasMoreElements():测试此枚举是否包含更多的元素
//nextElement():如果此枚举对象至少还有一个可提供的元素,则返回此枚举的下一个元素。
//ZipEntry:此类用于表示 ZIP 文件条目
ZipEntry zipEntry = (ZipEntry)entryEnum.nextElement();
if(zipEntry.isDirectory()){
System.out.println("这是一个目录.......");
}else{
//getSize():返回条目数据的未压缩大小;如果未知,则返回 -1。
System.out.println(zipEntry.getSize());
}
}
} catch (ZipException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
对于该段代码,如果生成的ZIP文件,即本例中的abc.zip,格式不正确,在打开ZIP文件时,即执行ZipFile zipFile = new ZipFile(file)时则抛出java.util.zip.ZipException: error in opening zip file。所谓格式不正确包括:从linux系统下载的文件在window系统上读写,或由.rar强转而成的.zip文件(二者在压缩和解压时的算法不一样)
0 0
- java.util.zip.ZipException: error in opening zip file
- java.util.zip.ZipException: error in opening zip file
- java.util.zip.ZipException: error in opening zip file
- java.util.zip.ZipException: error in opening zip file
- java.util.zip.ZipException:error in opening zip file
- java.util.zip.ZipException: error in opening zip file
- java.util.zip.ZipException: error in opening zip file
- java.util.zip.ZipException: error in opening zip file
- java.util.zip.ZipException: error in opening zip file
- java.util.zip.ZipException: error in opening zip file
- java.util.zip.ZipException: error in opening zip file
- zip 文件解压缩问题解决 java.util.zip.ZipException:error in opening zip file
- react native Exception in thread "main" java.util.zip.ZipException: error in opening zip file
- react native Exception in thread "main" java.util.zip.ZipException: error in opening zip file
- Exception in thread "main" java.util.zip.ZipException: error in opening zip file
- react native Exception in thread "main" java.util.zip.ZipException: error in opening zip file
- java.util.zip.ZipException: error in opening zip file有可能是压缩问题
- 在web服务器启动时: java.util.zip.ZipException: error in opening zip file
- Ubuntu下的文件压缩和解压
- 其他一些为自己的记录
- android 下改变默认的checkbox的 选中 和被选中 图片
- iOS 技术支持网址:
- 剑指offer:两个链表的第一个公共结点
- java.util.zip.ZipException: error in opening zip file
- JSP脚本的9个内置对象(三)——exception对象
- sql查询数值为null时处理成0
- 题目1172:哈夫曼树
- Android跨应用调用不返回启动应用页面问题
- Spring教程--IOC(控制反转)详解
- 前端数据实时校验
- C#指针一些操作
- 实体类(VO,DO,DTO)的划分与图解