标题:压缩文件代码
取消只看楼主
ehszt
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:40
帖 子:1728
专家分:3216
注 册:2015-12-2
结帖率:100%
已结贴  问题点数:20 回复次数:2 
压缩文件代码
import java.awt.*;
import *;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

import javax.swing.*;

import com.sun.nio.zipfs.ZipDirectoryStream;
public class Example{
    private void zip(String zipFileName,File inputFile)throws Exception{
    ZipOutputStream out=new ZipOutputStream(new FileOutputStream(zipFileName));
    zip(out,inputFile,"");
    System.out.println("压缩中...");
    out.close();
    }

private void zip(ZipDirectoryStream out,File f,String base)
        throws Exception{
    if(f.isDirectory()){
        File[] fl=f.listFiles();
        if(base.length()!=0){
            out.putNextEntry(new ZipEntry(base +"/"));
        }
        for(int i=0;i<fl.length;i++){
            zip(out,fl[i],base+fl[i]);
        }
    }else{
        out.putNextEntry(new ZipEntry(base));
        FileInputStream in =new FileInputStream(f);
        int b;
        System.out.println(base);
        while((b=in.read())!=-1){
            out.write(b);
        }
        in.close();
}
}
    public static void main(String[] temp){
        Example book =new Example();
        try{
            book.zip("E:/hello.zip",new File("E:/hello"));
            System.out.println("压缩完成");
        }catch(Exception ex){
            
        }
    }
}   

有问题,问题代码如下:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
    The method zip(ZipDirectoryStream, File, String) in the type Example is not applicable for the arguments (ZipOutputStream, File, String)

    at Example.zip(Example.java:12)
    at Example.main(Example.java:41)
怎么改好
搜索更多相关主题的帖子: java zip out Example new 
2018-03-17 15:42
ehszt
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:40
帖 子:1728
专家分:3216
注 册:2015-12-2
得分:0 
回复 2楼 疯狂的小a
哪里错了,能标注一下吗?
2018-03-17 19:27
ehszt
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:40
帖 子:1728
专家分:3216
注 册:2015-12-2
得分:0 
结贴,知道了。
2018-03-17 19:43



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-485343-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.675855 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved