1
我想下面寫一個java ZIP UTIL類:的Java ZipOutputStream問題
package fdbank.util;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
/**
* 解壓縮工具類
* @author [email protected]
*
*/
public class ZIPUtil {
private static void zip(File[] files, String dest) throws IOException{
ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(new File("dest")));
for(File file : files){
zip(file, zos);
}
zos.close();
}
private static void zip(File file, ZipOutputStream zos) throws IOException{
byte[] buf = new byte[2048];
@SuppressWarnings("unused")
int bytes = 0;
if(file.isDirectory()){
ZipEntry entry = new ZipEntry(file.getName());
zos.putNextEntry(entry);
for(File subFile : file.listFiles()){
zip(subFile, zos);
}
zos.closeEntry();
}
FileInputStream fis = new FileInputStream(file);
System.out.println(file.getName());
ZipEntry entry = new ZipEntry(file.getName());
zos.putNextEntry(entry);
while((bytes = fis.read(buf)) != -1){
zos.write(buf);
}
zos.closeEntry();
fis.close();
}
public static void compress(int archiveType, File[] files, String dest){
}
public static void main(String[] args){
try {
System.out.println("gan !!!!");
zip(new File[]{new File("F:\\ziptest\\1.bmp")},"c:\\ziptest.zip");
} catch (IOException e) {
e.printStackTrace();
}
}
}
我運行它,沒有錯誤,但壓縮文件並不創造! 我的代碼有什麼問題?
:C:d什麼是恥辱爲了我 – CaiNiaoCoder 2011-06-01 07:57:19