压缩文件代码
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)
怎么改好