壓縮多個檔案

2021-06-12 07:49:18 字數 1505 閱讀 8446

首先需要icsharpcode.sharpziplib.dll

新建filecompression.cs檔案

using system;

using system.collections.generic;

using system.io;

using system.threading;

using icsharpcode.sharpziplib.zip;

namespace lib

#region 加密、壓縮檔案

/// /// 壓縮檔案

///

/// 要打包的檔案列表

/// 目標檔名

/// 壓縮品質級別(0~9)

/// 休眠時間(單位毫秒)

public static void compress(listfilenames, string gzipfilename, int compressionlevel, int sleeptimer)

catch

// 方法二,將檔案分批讀入緩衝區

byte data = new byte[2048];

int size = 2048;

zipentry entry = new zipentry(path.getfilename(file.name));

entry.datetime = (file.creationtime > file.lastwritetime ? file.lastwritetime : file.creationtime);

s.putnextentry(entry);

while (true)

fs.close();

thread.sleep(sleeptimer);}}

finally

}#endregion

#region 解密、解壓縮檔案

/// /// 解壓縮檔案

///

/// 壓縮包檔名

/// 解壓縮目標路徑

public static void decompress(string gzipfile, string targetpath)

else

streamwriter.close();}}

}}

s.close();}}

#endregion

}}

使用:

protected void butderive_click(object sender, eventargs e)

//呼叫方法

string zipfilepath = "zipfile/" + datetime.now.tostring("yyyymmddhhmmssffff") + ".zip";

lib.filecompression.compress(filelist, zipserverfilepath, 5, 5);

}}

素材資源:

java壓縮多個檔案

首先建立乙個工具類,定義好介面,這裡的引數 1 filelist 多個檔案的path name 2 zipfilename 壓縮後的檔名 下面是 注釋已經很詳細了 public class ziputil 構建壓縮檔案file file zipfile new file zipfilename 初期...

java壓縮多個檔案

首先建立乙個工具類,定義好介面,這裡的引數 1 filelist 多個檔案的path name 2 zipfilename 壓縮後的檔名 下面是 注釋已經很詳細了 public class ziputil 構建壓縮檔案file file zipfile new file zipfilename 初期...

java壓縮多個檔案

首先建立乙個工具類,定義好介面,這裡的引數 1 filelist 多個檔案的path name 2 zipfilename 壓縮後的檔名 下面是 注釋已經很詳細了 public class ziputil 構建壓縮檔案file file zipfile new file zipfilename 初期...