ant zip 0kb
来源:互联网 发布:跟踪软件 编辑:程序博客网 时间:2024/04/30 12:41
利用ant包进行减压的时候,会发现0kb的文件 用inputStream.read()方法的时候会报错,而inputStream.available()返回的是1,所以目前还没有判断方法,只有将异常抛出,否则后面的程序也无法进行。如果有高手知道解决方法,可以给我留言
@SuppressWarnings("unchecked")public static void unZip(String zipfile, String destDir) {
destDir = destDir.endsWith( "/" ) ? destDir : destDir + "/" ;
byte b[] = new byte [1024];
int length;
ZipFile zipFile;
try {
zipFile = new ZipFile( new File(zipfile));
Enumeration enumeration = zipFile.getEntries();
ZipEntry zipEntry = null ;
while (enumeration.hasMoreElements()) {
zipEntry = (ZipEntry) enumeration.nextElement();
File loadFile = new File(destDir + zipEntry.getName());
if (!loadFile.getParentFile().exists()){
loadFile.getParentFile().mkdirs();
}
OutputStream outputStream = new FileOutputStream(loadFile);
InputStream inputStream = zipFile.getInputStream(zipEntry);
try{
while ((length = inputStream.read(b)) > 0)
outputStream.write(b, 0, length);
}catch(ZipException e){
if(e.getMessage().equals("invalid stored block lengths")){
System.out.println(loadFile+"为空文件"+zipEntry.getCompressedSize());
}
}
}
System.out.println("解压成功!");
} catch (IOException e) {
e.printStackTrace();
}
}
下面这个方法代码看起来更简洁,但是没有地方对0kb文件的判断。
public static void unzip1(String sourceZip, String destDir)
throws Exception {
try {
Project p = new Project();
Expand e = new Expand();
e.setProject(p);
e.setSrc(new File(sourceZip));
e.setOverwrite(false);
e.setDest(new File(destDir));
/*
* ant下的zip工具默认压缩编码为UTF-8编码, 而winRAR软件压缩是用的windows默认的GBK或者GB2312编码
* 所以解压缩时要制定编码格式
*/
e.setEncoding("gbk");
e.execute();
} catch (Exception e) {
throw e;
}
}
- ant zip 0kb
- ant zip打包
- Ant打包生成zip
- ant.jar打ZIP包
- Groovy : zip files by ant
- Ant 压缩打包zip文件
- 使用ant实现Zip文件压缩和解压缩Zip文件
- apach ant 压缩和解压缩zip文件
- zip,obfuscate,war的ant脚本
- java 通过ant 实现压缩zip包
- java打zip包 基于ant
- 使用ant.jar进行文件zip压缩
- ANT:生成doc、打包zip、FTP
- 用ant包实现zip文件解压的类
- 转载 使用ant.jar进行文件zip压缩
- ant 为项目生成doc文档 并打包成zip
- java使用Apache的ant压缩和解压文件(zip)
- 使用Ant实现zip/tar的压缩与解压
- 解决HttpClient访问URL中文问题
- LocalAlloc,VirtualAlloc,malloc,new 的异同
- 关闭福昕阅读器开始页(Start Page)
- java混淆器Proguard 的使用
- effective C++读书笔记(五)
- ant zip 0kb
- @Override错误
- 万圣节档案:微软的反Linux战略15周年回顾
- Linux net-snmp-5.7.2安装配置
- OCP-1Z0-053-V12.02-204题
- lucene+查询
- ImageMagick--打水印
- ActionContext和ServletActionContext小结
- 十七 Django 1.5.4 Sqlite3 Context Processors