国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計 > 正文

用Java壓縮文件或目錄下的所有文件

2019-11-18 15:26:29
字體:
供稿:網(wǎng)友


import java.io.File;
import org.apache.tools.zip.ZipOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
/**
* @author tyrone
*
*/
public class DirectoryZip {
/**
  *@param inputFileName, file or directory waiting for zipping ,outputFileName output file name
  *
  */
public void zip(String inputFileName,String outputFileName) throws Exception {
  ZipOutputStream out = new ZipOutputStream(new FileOutputStream(outputFileName));
  zip(out, new File(inputFileName), "");
  System.out.  out.close();
}
private void zip(ZipOutputStream out, File f, String base) throws Exception {
  if (f.isDirectory()) {
   File[] fl = f.listFiles();
   if (System.getProperty("os.name").startsWith("Windows")){
    out.putNextEntry(new org.apache.tools.zip.ZipEntry(base + "http://"));
    base = base.length() == 0 ? "" : base + "http://";
   }
   else{
    out.putNextEntry(new org.apache.tools.zip.ZipEntry(base + "/"));
    base = base.length() == 0 ? "" : base + "/";
   }
   for (int i = 0; i < fl.length; i++) {
    zip(out, fl[i], base + fl[i].getName());
   }
  }
  else {
   out.putNextEntry(new org.apache.tools.zip.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[] args){
  DirectoryZip m_zip=new DirectoryZip();
  try{
   m_zip.zip(args[0],"release//2005.zip");
  }catch(Exception ex){
   ex.printStackTrace();
  }
}
}



發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 大同市| 洪江市| 漳平市| 夏河县| 木兰县| 监利县| 泽库县| 平塘县| 耒阳市| 灵璧县| 成武县| 吉安市| 和林格尔县| 建阳市| 芷江| 淄博市| 布拖县| 仙居县| 界首市| 永顺县| 璧山县| 杭锦后旗| 泌阳县| 黄浦区| 峡江县| 西华县| 交城县| 丁青县| 哈密市| 柞水县| 江门市| 九龙坡区| 湖南省| 渝北区| 客服| 偃师市| 福州市| 新安县| 柳林县| 盱眙县| 麟游县|