<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      java 將文件夾進行壓縮,按指定大小進行分卷壓縮

      使用方法:
      SplitZip splitZip = new SplitZip();
      splitZip.start(file.getPath(),file.getPath());

      package ext.xxx.util;
      
      import java.io.*;
      import java.util.zip.*;
      
      import static org.apache.commons.lang3.StringUtils.isBlank;
      
      /**
       * 分卷壓縮工具
       */
      public class SplitZip {
          private static final int MAX_ZIP_SIZE = 1024 * 1024 * 300; // 300MB,可以改為自己想要的大小
          private  ZipOutputStream currentZipOutputStream = null;
          private  File currentZipFile = null;
          private  long totalBytesWritten = 0;
          private  int currentZipCount = 0;
          private  String basePath = ""; // 基本路徑,用于在ZIP中保持相對路徑
      
          private String outZipName = "";//輸出壓縮包的名稱
      
          public void addFileToZip(File fileToAdd, String parentPath) throws IOException {
              long approximateFileSize = getApproximateFileSize(fileToAdd);//計算要壓縮的文件(文件夾)大小
              if (currentZipOutputStream == null || (totalBytesWritten + approximateFileSize > MAX_ZIP_SIZE && totalBytesWritten != 0)) {
                  closeCurrentZip();
                  openNewZip();
              }
      
              if (fileToAdd.isDirectory()) {
                  File[] files = fileToAdd.listFiles();
                  if (files != null) {
                      for (File file : files) {
                          addFileToZip(file, parentPath + fileToAdd.getName() + "/");
                      }
                  }
              } else {
                  ZipEntry zipEntry = new ZipEntry(parentPath + fileToAdd.getName());
                  currentZipOutputStream.putNextEntry(zipEntry);
      
                  FileInputStream fis = new FileInputStream(fileToAdd);
                  byte[] buffer = new byte[1024];
                  int length;
                  while ((length = fis.read(buffer)) >= 0) {
                      currentZipOutputStream.write(buffer, 0, length);
                      totalBytesWritten += length; // 更新已寫入的總字節數
                  }
                  fis.close();
                  currentZipOutputStream.closeEntry();
              }
          }
      
          private long getApproximateFileSize(File file) {
              if (file.isDirectory()) {
                  long length = 0;
                  File[] files = file.listFiles();
                  if (files != null) {
                      for (File childFile : files) {
                          length += getApproximateFileSize(childFile);
                      }
                  }
                  return length;
              } else {
                  return file.length();
              }
          }
      
          private void openNewZip() throws IOException {
              totalBytesWritten = 0; // 重置已寫入的字節數
              currentZipCount++;
              currentZipFile = new File(outZipName + "_" + currentZipCount + ".zip");
              currentZipOutputStream = new ZipOutputStream(new FileOutputStream(currentZipFile));
          }
      
          private void closeCurrentZip() throws IOException {
              if (currentZipOutputStream != null) {
                  currentZipOutputStream.close();
                  currentZipOutputStream = null;
              }
          }
      
          public void zipDirectory(File directoryToZip, String baseDirectoryPath) throws IOException {
              basePath = baseDirectoryPath;
              if (directoryToZip.isDirectory()) {
                  addFileToZip(directoryToZip, "");
              } else {
                  throw new IOException("The specified path is not a directory.");
              }
              closeCurrentZip(); // 確保關閉最后一個ZIP文件  
          }
      
          /**
           *
           * @param folder 要壓縮的文件夾
           * @param targetZipName 生成壓縮包的名稱
           */
          public void start(String folder,String targetZipName) throws Exception {
              if (isBlank(folder) || isBlank(targetZipName)) {
                  throw new Exception("不能壓縮。。。。。。");
              }
              outZipName = targetZipName;
              File dirToZip = new File(folder); // 替換為你要壓縮的目錄路徑
              String baseDirPath = dirToZip.getName(); // 通常我們想要基于目錄名來創建ZIP文件的根目錄
              try {
                  zipDirectory(dirToZip, baseDirPath + "/");
              } catch (IOException e) {
                  e.printStackTrace();
              }
          }
      
          public static void main(String[] args) throws Exception {
              SplitZip splitZip = new SplitZip();
              splitZip.start("D:\\新建文件夾","D:\\新建文件夾");
       } }

       




      posted @ 2024-04-03 15:43  何足道66  閱讀(1150)  評論(0)    收藏  舉報
      主站蜘蛛池模板: 亚洲老熟女一区二区三区| 亚洲精品沙发午睡系列| 国产深夜福利视频在线| 91偷自国产一区二区三区| 亚洲毛片多多影院| 国产精品国产三级国快看| 久久亚洲精品11p| 国产成人精品一区二三区| 国产一区二区不卡在线| 国产成人av一区二区三区不卡| 日韩一区二区三区精品区| 国产男女猛烈无遮挡免费视频| 亚洲精品福利一区二区三区蜜桃 | 巨爆乳中文字幕爆乳区| 国产视频一区二区三区四区视频| 日本无遮挡真人祼交视频| 中文 在线 日韩 亚洲 欧美 | 东京热人妻无码一区二区av| 強壮公弄得我次次高潮A片| 四虎永久在线精品无码视频| 中文国产乱码在线人妻一区二区| 日本午夜精品一区二区三区电影| 欧美熟妇xxxxx欧美老妇不卡| 日本精品极品视频在线| 综合色天天久久| 国内精品一区二区不卡| 免费区欧美一级猛片| A级毛片100部免费看| 她也色tayese在线视频| 国产成人av电影在线观看第一页| 丰满多毛的大隂户视频| 国产一区二区日韩在线| 欧美午夜理伦三级在线观看| 一本加勒比hezyo无码人妻| 中文字幕人妻av12| 亚洲精品无码成人aaa片| 国内精品卡一卡二卡三| 亚洲另类丝袜综合网| 十八禁午夜福利免费网站 | 国产中文三级全黄| 在线播放亚洲人成电影|