欧美一级特黄大片做受成人-亚洲成人一区二区电影-激情熟女一区二区三区-日韩专区欧美专区国产专区

Java多文件以ZIP壓縮包導(dǎo)出的實(shí)現(xiàn)方法-創(chuàng)新互聯(lián)

本文實(shí)例為大家分享了Java多文件以ZIP壓縮包導(dǎo)出的具體代碼,供大家參考,具體內(nèi)容如下

站在用戶的角度思考問題,與客戶深入溝通,找到蒙城網(wǎng)站設(shè)計與蒙城網(wǎng)站推廣的解決方案,憑借多年的經(jīng)驗(yàn),讓設(shè)計與互聯(lián)網(wǎng)技術(shù)結(jié)合,創(chuàng)造個性化、用戶體驗(yàn)好的作品,建站類型包括:成都網(wǎng)站設(shè)計、成都網(wǎng)站建設(shè)、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣、域名注冊、雅安服務(wù)器托管、企業(yè)郵箱。業(yè)務(wù)覆蓋蒙城地區(qū)。

1、使用java實(shí)現(xiàn)吧服務(wù)器的圖片打包成一個zip格式的壓縮包導(dǎo)出,多個文件打包導(dǎo)出。
2、代碼如下:

**ImageByteUtil.java**

public class ImageByteUtil{
  private static float QUALITY = 0.6f;
  public static void compressZip(List<File> listfiles, OutputStream output,String encode, boolean compress,String alias){
  ZipOutputStream zipStream = null;
  try {
      zipStream = new ZipOutputStream(output);
      for (File file : listfiles){
        compressZip(file, zipStream, compress,alias+"_"+(listfiles.indexOf(file)+1));
      }
    } catch (Exception e) {
      e.printStackTrace();
    }finally {
      try { 
        if (zipStream != null) { 
          zipStream.close(); 
        } 
      } catch (IOException e) { 
        e.printStackTrace(); 
      }
    }
  }

private static void compressZip(File file, ZipOutputStream zipStream, 
      boolean compress,String alias) throws Exception{
    FileInputStream input = null;
    try {
      input = new FileInputStream(file); 
      //zip(input, zipStream, file.getName(), compress); 
      zip(input, zipStream, alias+"."+file.getName().substring(file.getName().lastIndexOf(".")+1), compress);
    } catch (Exception e) {
      e.printStackTrace();
    }finally {
      try { 
        if(input != null) 
          input.close(); 
      } catch (IOException e) { 
        e.printStackTrace(); 
      }
    }
  }

private static void zip(InputStream input, ZipOutputStream zipStream, 
      String zipEntryName, boolean compress) throws Exception{
      byte[] bytes = null; 
    BufferedInputStream bufferStream = null; 
    try { 
      if(input == null) 
        throw new Exception("獲取壓縮的數(shù)據(jù)項失敗! 數(shù)據(jù)項名為:" + zipEntryName); 
      // 壓縮條目不是具體獨(dú)立的文件,而是壓縮包文件列表中的列表項,稱為條目,就像索引一樣 
      ZipEntry zipEntry = new ZipEntry("圖片/"+zipEntryName);
      // 定位到該壓縮條目位置,開始寫入文件到壓縮包中 
      zipStream.putNextEntry(zipEntry);
      if (compress) { 
        bytes = ImageByteUtil.compressOfQuality(input, 0); 
        zipStream.write(bytes, 0, bytes.length); 
      } else {
        bytes = new byte[1024 * 5];// 讀寫緩沖區(qū) 
        bufferStream = new BufferedInputStream(input);// 輸入緩沖流 
        int read = 0; 
        while ((read = bufferStream.read(bytes)) != -1) {
          zipStream.write(bytes, 0, read); 
        } 
      } 
    } catch (IOException e) { 
      e.printStackTrace(); 
    } finally { 
      try { 
        if (null != bufferStream) 
          bufferStream.close(); 
      } catch (IOException e) { 
        e.printStackTrace(); 
      } 
    }
  }

  public static byte[] compressOfQuality(File file, float quality) throws Exception{
    byte[] bs = null; 
    InputStream input = null; 
    try { 
      input = new FileInputStream(file); 
      bs = compressOfQuality(input,quality);
    } catch (Exception e) { 
      e.printStackTrace(); 
    } finally { 
      try { 
        if (input != null) 
          input.close(); 
      } catch (IOException e) { 
        e.printStackTrace(); 
      } 
    } 
    return bs;
  }

  public static byte[] compressOfQuality(InputStream input, float quality) 
      throws Exception {
      ByteArrayOutputStream output = null; 
    try { 
      output = new ByteArrayOutputStream(); 
      if(quality == 0){ 
        Thumbnails.of(input).scale(1f).outputQuality(QUALITY) 
        .toOutputStream(output); 
      } else { 
        Thumbnails.of(input).scale(1f).outputQuality(quality).toOutputStream(output); 
      } 
      return output.toByteArray(); 
    } catch (Exception e) { 
      e.printStackTrace(); 
    } finally { 
      try { 
        if (output != null) 
          output.close(); 
      } catch (IOException e) { 
        e.printStackTrace(); 
      } 
    } 
    return null;
  }
}

本文題目:Java多文件以ZIP壓縮包導(dǎo)出的實(shí)現(xiàn)方法-創(chuàng)新互聯(lián)
分享網(wǎng)址:http://aaarwkj.com/article16/dppcgg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供微信公眾號、網(wǎng)站策劃、企業(yè)網(wǎng)站制作、網(wǎng)站營銷、動態(tài)網(wǎng)站、網(wǎng)頁設(shè)計公司

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

小程序開發(fā)
国产在线一区二区三区蜜桃| 国产91九色在线播放| 热久久这里只有精品网址| 日本免费91午夜视频| 激情四射五月天亚洲婷婷| 国产精品一区二区三区专区| 亚洲一区二区视频在线播放| 99热这里只有精品中文有码| 中文字幕五月久久婷热| 91精品国语对白人妻刺激| 中文字幕欧美人妻在线| 熟女aaa一区二区午夜| 日韩最新人妻在线不卡| 欧美日韩国产天天干| 女人高潮被爽到呻吟在线| 91午夜福利视频免费播放| 色综合视频二区偷拍在线| 国产日产亚洲综合一区| 人人妻人人澡人人爽久久av| 亚洲伊人久久一区二区| 亚洲一区二区三区小蜜桃| 日韩精品视频一区二区在线观看| 精品久久少妇激情视频| 视频一区二区三区不卡| 国产伦理免费精品中文字幕| 漂亮人妻中文字幕av| 高潮少妇高潮少妇av| 国产亚洲欧美久久精品| 国产亚洲中文久久网久久| 国产实拍之强伦奸在线观看| 国产精品久久久久久久久| 在线观看91高清视频| 久久精品国产一区电影| 亚洲六月丁香六月婷婷| 人妻久久久久久精品99| 成人深夜福利视频在线| 成人精品颜射少妇内射| 另类国产人妖免费视频网站大全| 亚洲欧洲日韩另类在线| 美女诱惑丝袜国产国产av丝袜| 国内丰满少妇嗷嗷叫在线播放|