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

首頁 > 網站 > 建站經驗 > 正文

JS_P上面實現目錄壓縮

2019-11-02 15:44:24
字體:
來源:轉載
供稿:網友

  zip方法 zipPath參數為保存zip的文件路徑 srcPath參數為需要壓縮的目錄 在linux window上面測試無問題!主要是編碼問題比較麻煩~要是有其他異常 請留言 或者 有什么更好的方法 歡迎給更多的意見

  //zip zhe folder

  void zip(String zipPath, String srcPath,javax.servlet.jsp.JspWriter out) throws Exception {

  FileOutputStream output = null;

  ZipOutputStream zipOutput = null;

  try{

  output = new FileOutputStream(zipPath);

  zipOutput = new ZipOutputStream(output);

  zipEntry(zipOutput,srcPath,srcPath,zipPath);

  }catch(Exception e){

  out.print("file zip error");

  }finally{

  if(zipOutput!=nul

雷人圖片大全[www.62-6.com/1/leirentupian/]
l)zipOutput.close();

  }

  out.print("zip ok"+zipPath);

  }

  //add the zip entry

  void zipEntry(ZipOutputStream zipOs, String initPath,String filePath,String zipPath) throws Exception {

  String entryName = filePath;

  File f = new File(filePath);

  if (f.isDirectory()){// ??

  String[] files = f.list();

  for(int i = 0; i < files.length; i++)

  zipEntry(zipOs, initPath, filePath + File.separator + files[i],zipPath);

  return;

  }

  String chPh = initPath.substring(initPath.lastIndexOf("/") + 1);// ?????

  int idx=initPath.lastIndexOf(chPh);

  if (idx != -1) {

  entryName = filePath.substring(idx);

  }

  ZipEntry entry;

  entry = new ZipEntry(entryName);

  File ff = new File(filePath);

  if(ff.getAbsolutePath().equals(zipPath))return;

  entry.setSize(ff.length());

  entry.setTime(ff.lastModified());

  //the CRC efficacy

  entry.setCrc(0);

  CRC32 crc = new CRC32();

  crc.reset();

  zipOs.putNextEntry(entry);

  int len = 0;

  byte[] buffer = new byte[2048];

  int bufferLen = 2048;

  FileInputStream input =null;

  try{

  input = new FileInputStream(filePath);

  while ((len = input.read(buffer, 0, bufferLen)) != -1) {

  zipOs.write(buffer, 0, len);

  crc.update(buffer, 0, len);

  }

  }catch(Exception e){

  }finally{

  if(input!=null)input.close();

  }

  entry.setCrc(crc.getValue());

  }

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 都匀市| 伽师县| 定安县| 武山县| 新河县| 北碚区| 福贡县| 嘉黎县| 辽宁省| 承德县| 丽江市| 中西区| 马尔康县| 凤庆县| 桐庐县| 库伦旗| 海兴县| 昂仁县| 改则县| 九龙县| 叶城县| 来安县| 宝坻区| 武城县| 绥宁县| 乌兰县| 定远县| 贵溪市| 西林县| 偃师市| 霸州市| 长葛市| 商洛市| 长乐市| 蛟河市| 光山县| 临汾市| 会宁县| 英超| 繁昌县| 武邑县|