压缩文件
import de.schlichtherle.util.zip.ZipEntry;
import de.schlichtherle.util.zip.ZipOutputStream;
truezip-6.6.jar
private static void zipFile(String targetName, File sourceFile, File targetFilezip)
throws FileNotFoundException, IOException {
//压缩文件 start java中常用ZipOutStream进行文件的压缩,用ZipInputStream对文件进行解压
FileInputStream inputstream_target = new FileInputStream(sourceFile);
BufferedInputStream bufferedInputStream =new BufferedInputStream(inputstream_target);
ZipOutputStream zipOutputStream = new ZipOutputStream( new FileOutputStream (targetFilezip),"UTF-8");
BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(zipOutputStream) ;
try{
zipOutputStream.putNextEntry(new ZipEntry(targetName));
byte[] b = new byte[1024*5];
@SuppressWarnings("unused")
int len;
while(( len=bufferedInputStream.read(b))!=-1){
bufferedOutputStream.write(b);
}
zipOutputStream.flush();
zipOutputStream.closeEntry();
zipOutputStream.close();
bufferedInputStream.close();
inputstream_target.close();
}catch(Exception e ){
e.printStackTrace();
}
finally {
if(null!=inputstream_target){
inputstream_target.close();
}
if(null!=bufferedInputStream){
bufferedInputStream.close();
}
}
}