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

Java壓縮解壓縮工具類

本文實(shí)例為大家分享了Java壓縮解壓縮工具類的具體代碼,供大家參考,具體內(nèi)容如下

創(chuàng)新互聯(lián)建站專注于廣昌網(wǎng)站建設(shè)服務(wù)及定制,我們擁有豐富的企業(yè)做網(wǎng)站經(jīng)驗(yàn)。 熱誠為您提供廣昌營銷型網(wǎng)站建設(shè),廣昌網(wǎng)站制作、廣昌網(wǎng)頁設(shè)計(jì)、廣昌網(wǎng)站官網(wǎng)定制、小程序設(shè)計(jì)服務(wù),打造廣昌網(wǎng)絡(luò)公司原創(chuàng)品牌,更為您提供廣昌網(wǎng)站排名全網(wǎng)營銷落地服務(wù)。

package com.wdy.tools.utils.pressuitl;
 
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import java.util.zip.ZipInputStream;
import java.util.zip.ZipOutputStream;
 
import org.apache.commons.logging.Log;
 
import com.wdy.tools.utils.LogUtil;
 
/**
 * 壓縮/解壓縮工具類(zip格式)
 * 
 * @author wdy
 * @date 2016-08-23
 */
public class PressUtil {
 
 private static final Log log = LogUtil.getLog(PressUtil.class);
 
 
 
 public static void main(String[] args) {
// PressUtil.ZipMultiFile("d:\\nwp_trans\\nwp_h\\", "d:\\nwp_trans\\nwp_h\\wdy.zip");
 String sourceFilePath = "d:\\nwp_trans\\nwp_h\\"; 
   String zipFilePath = "d:\\nwp_trans\\nwp_h\\"; 
   String fileName = "wdy"; 
   boolean flag = PressUtil.fileToZip(sourceFilePath, zipFilePath, fileName);
   if(flag){ 
   log.info("文件打包成功!"); 
   }else{ 
   log.info("文件打包失敗!"); 
   } 
 }
 
 /** 
  * 將存放在sourceFilePath目錄下的源文件,打包成fileName名稱的zip文件,并存放到zipFilePath路徑下 
  * @param sourceFilePath :待壓縮的文件路徑 
  * @param zipFilePath :壓縮后存放路徑 
  * @param fileName :壓縮后文件的名稱(不包括擴(kuò)展名) 
  * @return 
  */ 
 @SuppressWarnings("resource")
 public static boolean fileToZip(String sourceFilePath,String zipFilePath,String fileName){ 
  boolean flag = false; 
  File sourceFile = new File(sourceFilePath); 
  FileInputStream fis = null; 
  BufferedInputStream bis = null; 
  FileOutputStream fos = null; 
  ZipOutputStream zos = null; 
   
  if(sourceFile.exists() == false){ 
   log.info("待壓縮的文件目錄:"+sourceFilePath+"不存在.");
  }else{ 
   try { 
    File zipFile = new File(zipFilePath + "/" + fileName +".zip"); 
    if(zipFile.exists()){ 
     log.info(zipFilePath + "目錄下存在名字為:" + fileName +".zip" +"打包文件.");
    }else{ 
     File[] sourceFiles = sourceFile.listFiles(); 
     if(null == sourceFiles || sourceFiles.length<1){ 
      log.info("待壓縮的文件目錄:" + sourceFilePath + "里面不存在文件,無需壓縮.");
     }else{ 
      fos = new FileOutputStream(zipFile); 
      zos = new ZipOutputStream(new BufferedOutputStream(fos)); 
      byte[] bufs = new byte[1024*10]; 
      for(int i=0;i<sourceFiles.length;i++){ 
       //創(chuàng)建ZIP實(shí)體,并添加進(jìn)壓縮包 
       ZipEntry zipEntry = new ZipEntry(sourceFiles[i].getName()); 
       zos.putNextEntry(zipEntry); 
       //讀取待壓縮的文件并寫進(jìn)壓縮包里 
       fis = new FileInputStream(sourceFiles[i]); 
       bis = new BufferedInputStream(fis, 1024*10); 
       int read = 0; 
       while((read=bis.read(bufs, 0, 1024*10)) != -1){ 
        zos.write(bufs,0,read); 
       } 
      } 
      flag = true; 
     } 
    } 
   } catch (FileNotFoundException e) { 
    e.printStackTrace(); 
    throw new RuntimeException(e); 
   } catch (IOException e) { 
    e.printStackTrace(); 
    throw new RuntimeException(e); 
   } finally{ 
    //關(guān)閉流 
    try { 
     if(null != bis) bis.close(); 
     if(null != zos) zos.close(); 
    } catch (IOException e) { 
     e.printStackTrace(); 
     throw new RuntimeException(e); 
    } 
   } 
  } 
  return flag; 
 } 
 
 /**
 * 壓縮單個(gè)文件
 * @param filePath 要被壓縮的文件的全路徑,包含文件名d:/hello.txt
 * @param zipPath 壓縮后的全路徑,包含文件名d:/hello.zip
 */
 public static void zipOneFile(String filePath, String zipPath) {
 try {
 File file = new File(filePath);
 File zipFile = new File(zipPath);
 InputStream input = new FileInputStream(file);
 ZipOutputStream zipOut = new ZipOutputStream(new FileOutputStream(zipFile));
 zipOut.putNextEntry(new ZipEntry(file.getName()));
 int temp = 0;
 while ((temp = input.read()) != -1) {
 zipOut.write(temp);
 }
 input.close();
 zipOut.close();
 } catch (Exception e) {
 e.printStackTrace();
 }
 }
}

以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持創(chuàng)新互聯(lián)。

文章題目:Java壓縮解壓縮工具類
網(wǎng)站鏈接:http://aaarwkj.com/article0/iihoio.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供商城網(wǎng)站、網(wǎng)站改版、、微信小程序關(guān)鍵詞優(yōu)化、ChatGPT

廣告

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

成都seo排名網(wǎng)站優(yōu)化
中文字幕欧美人妻在线| 亚洲视频在线的视频在| 一区二区在线日韩欧美| 一区二区亚洲免费的视频| 一本之道久久成人综合| 久久国产精品99亚洲| 日韩精品 在线一区二区| 日本黄色录像在线观看| 哪里可以看日韩免费毛片| 91精品在线观看第一页| 日韩视频 一区 二区| 亚洲品质一区二区三区| 亚洲中文字幕精品一区二区三区| 国产精品国产不卡在线| 亚洲中文字幕女同系列av专区| 国产精品白嫩初高中害羞小美女| 在线免费观看日韩黄片| 少妇高潮喷水下面的水| 人妻av在线中文字幕| av欧美激情在线观看| 99久久精品费精品国产风间由美| 亚洲综合精品久久久一区| 亚洲中文字幕乱码一二三| 亚洲女人下体毛茸茸视频| 99久久伊人精品综合观看| 自拍国语对白在线视频| 欧美生活一区二区三区| 成人国产在线欧美精品| 日韩精品中文字幕电影| 人妇乱系列中文字幕人妻| 日日夜夜精品天天综合| 婷婷激情六月中文字幕| 91麻豆亚洲国产成人久久| 欧美日韩中文国产天堂| 97免费在线视频观看| 少妇高潮喷水下面的水| 91无人区一区二区三乱码| 日韩在线欧美在线一区二区| 日韩av毛片在线观看| 亚洲午夜精品理论在线不卡| 国内传媒视频免费观看|