`
JadeLuo
  • 浏览: 410878 次
  • 性别: Icon_minigender_1
  • 来自: 珠海
社区版块
存档分类
最新评论

生成zip文件

XML 
阅读更多
expected 25847 but got 25900 bytes)

public void zip(File file,String fileFileName) throws IOException{
String classpath;
ZipOutputStream zos = null;
FileInputStream is = null;
ZipInputStream zipis = null;
try {
classpath = GetProjectRoot.getProjectRoot();
is = new FileInputStream(file);
// 把文件输入流转换为压缩输入流
zipis = new ZipInputStream(is);
zos= new ZipOutputStream(new FileOutputStream(classpath+"jpdl/"+fileFileName));
ZipEntry entry = null;
//验证是否包含一个xml文件和png图片,并将xml和png图片进行压缩
        while ((entry = zipis.getNextEntry()) != null) {
            if(entry.getName().indexOf(".xml")>0 || entry.getName().indexOf(".png")>0){//后缀不可能在第一位出现所以是>0
            zos.putNextEntry(new ZipEntry(entry.getName()));
            byte data[] = new byte[1024];
int len=0;
while((len=zipis.read(data))!=-1){
zos.write(data, 0, len);
}
            }
        }
} catch (Exception e) {
e.printStackTrace();

}finally{
if(is!=null){
is.close();
}
if(zipis!=null){
zipis.close();
}
if(zos!=null){
zos.close();
}
}
}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics