C 壓縮檔案

2021-05-08 09:12:13 字數 855 閱讀 8123

首先新增system.io.com[pression

注意deflatestream類不能用來壓縮大小超過4gb的檔案。

gzipstream同樣不能用來壓縮大小超過4gb的檔案。

public void compressfile(string srcfile,string dstfile)

if (!file.exists(srcfile))

throw new filenotfoundexception();

byte buffer;

tryusing (filestream srcstream=new filestream(srcfile,filemode.open,fileaccess.read,fileshare.read))

buffer=new byte[srcstream.length];

int checkcounter=srcstream.read(buffer,0,buffer.length);

using(filestream dststream=new filestream(dstfile,filemode.openorcreate,fileaccess.write))

using(gzipstream comstream=new gzipstream(dststream,compressionmode.compress,true))

comstream.write(buffer,0,buffer.length);

catch (expection ex)

{ex.source="函式compressfile() ";

throw (ex);

以上代買摘自《visual c#2005檔案io與資料訪問秘訣》機械工業出版社

C 壓縮檔案

c 壓縮檔案 方法1 filepath想要壓縮檔案的位址 zippath輸出壓縮檔案的位址 private void getfiletozip string filepath,string zippath 方法2 private void filetozip string path,string a...

C 壓縮檔案

最近悟出來乙個道理,在這兒分享給大家 學歷代表你的過去,能力代表你的現在,學習代表你的將來。十年河東十年河西,莫欺少年窮。學無止境,精益求精 上一節講述了c webapi傳參之post請求 ajax 本節 c 壓縮檔案的方法,直接上 如下public class ziputility filestr...

c 壓縮檔案

引用 using system using system.collections.generic using system.text using microsoft.win32 using system.io using system.diagnostics 獲取winrar.exe路徑 winra...