檔案壓縮和解壓縮類

2022-09-13 05:42:13 字數 2270 閱讀 8618

using system;

using system.collections.generic;

using system.text;

using system.io;

using icsharpcode.sharpziplib;

using icsharpcode.sharpziplib.zip;

using icsharpcode.sharpziplib.checksums;

public class zipclass

}catch

finally

if (entry != null)

gc.collect();

gc.collect(1);

}folders = directory.getdirectories(foldertozip);

foreach (string folder in folders)

}return res;

}///

/// 壓縮目錄

///

/// 待壓縮的資料夾,全路徑格式

/// 壓縮後的檔名,全路徑格式

///

public static bool zipfiledictory(string foldertozip, string zipedfile, string password)

zipoutputstream s = new zipoutputstream(file.create(zipedfile));

s.setlevel(6);

s.password = password;

res = zipfiledictory(foldertozip, s, "");

s.finish();

s.close();

return res;

}///

/// 壓縮檔案

///

/// 要進行壓縮的檔名

/// 壓縮後生成的壓縮檔案名

///

public static bool zipfile(string filetozip, string zipedfile, string password)

//filestream fs = null;

filestream zipfile = null;

zipoutputstream zipstream = null;

zipentry zipentry = null;

bool res = true;

trycatch (exception ex)

finally

if (zipstream != null)

if (zipfile != null)

gc.collect();

gc.collect(1);

}return res;

}///

/// 壓縮檔案 和 資料夾

///

/// 待壓縮的檔案或資料夾,全路徑格式

/// 壓縮後生成的壓縮檔案名,全路徑格式

///

public static bool zip(string filetozip, string zipedfile, string password)

else if (file.exists(filetozip))

else}}

////// 解壓類

///

public class unzipclass

if (!directory.exists(zipedfolder))

zipinputstream s = null;

zipentry theentry = null;

string filename;

filestream streamwriter = null;

trystrunzipname = filename;

strextension = system.io.path.getextension(filename);

streamwriter = file.create(filename);

int size = 2048;

byte data = new byte[2048];

while (true)

else}}

}}finally

if (theentry != null)

if (s != null)

gc.collect();

gc.collect(1);}}

}}

檔案的壓縮和解壓縮

ios中對檔案的解壓縮處理通常都是利用第三方框架,實現解壓縮,接下來就來看看吧。使用步驟 解壓檔案 nsstring zippath path to your zip file nsstring destinationpath path to the folder where you want it...

檔案的壓縮和解壓縮

import ssziparchive.h 方法一 第乙個引數 壓縮檔案的存放位置 第二個引數 要壓縮那些檔案 路徑 這裡面是乙個陣列,陣列當中都是我們需要壓縮檔案路徑 建立陣列nsarray arraym ssziparchive createzipfileatpath test.zip with...

Linux檔案壓縮和解壓縮

壓縮 tar 引數 生成的壓縮包的名字 要壓縮的檔案 檔案 目錄 引數 c 生成壓縮檔案 z 使用gzip的方式進行壓縮 j 使用bzip2壓縮 v 顯示壓縮資訊 可以省略 f 指定壓縮包名 壓縮包名 隨便指定,字尾需要自己指定 如果壓縮使用gzip,引數就是 z,包名 tar.gz 如果壓縮使用b...