小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

C#調(diào)用7z實(shí)現(xiàn)文件的壓縮與解壓

 頭號(hào)碼甲 2020-04-24

1.關(guān)于7z

首先在這里先介紹一下7z壓縮軟件,7z是一種主流的 壓縮格式,它擁有極高的壓縮比。在計(jì)算機(jī)科學(xué)中,7z是一種可以使用多種壓縮算法進(jìn)行數(shù)據(jù)壓縮的檔案格式。主要有以下特點(diǎn):

  • 來源且模塊化的組件結(jié)構(gòu)
  • 最高的壓縮比
  • 強(qiáng)大的AES-256加密
  • 可更改配置的壓縮算法
  • 支持操大文件
  • 支持多線程壓縮
  • 具有多種壓縮文件格式
2.解壓縮實(shí)現(xiàn)代碼
實(shí)現(xiàn)對(duì)文件的解壓縮方法是通過cmd命令,調(diào)用7z程式通過cmd命令實(shí)現(xiàn)對(duì)文件進(jìn)行解壓和壓縮的操作,具體實(shí)現(xiàn)代碼如下:
  • 壓縮代碼
壓縮的cmd命令:"7Z a -tzip " + zipPath + "  " + filePath;
public ExecutionResult CompressFile(string filePath, string zipPath)//運(yùn)行DOS命令
        {
            ExecutionResult exeRes = new ExecutionResult();
            exeRes.Status = true;
            try
            {
                Process process = new Process();
                process.StartInfo.FileName = "cmd.exe";
                string message = "";
                string command1 = "c:";
                string command2 = @"cd\";
                string command3 = @"cd C:\Progra~1\7-Zip";
                string command4 = "";


                command4 = "7Z a -tzip " + zipPath + "  " + filePath;

                process.StartInfo.UseShellExecute = false;
                process.StartInfo.RedirectStandardInput = true;
                process.StartInfo.RedirectStandardOutput = true;
                process.StartInfo.RedirectStandardError = true;
                process.StartInfo.CreateNoWindow = true;
                process.Start();
                process.StandardInput.WriteLine(command1);
                process.StandardInput.WriteLine(command2);
                process.StandardInput.WriteLine(command3);
                process.StandardInput.WriteLine(command4);
                process.StandardInput.WriteLine("exit");
                message = process.StandardOutput.ReadToEnd(); //要等壓縮完成后才可以來抓取這個(gè)壓縮文件

                process.Close();
                if (!message.Contains("Everything is Ok"))
                {
                    exeRes.Status = false;
                    exeRes.Message = message;
                }
                else
                {
                    exeRes.Anything = zipPath;
                }
            }
            catch (Exception ex)
            {
                exeRes.Message = ex.Message;
            }

            return exeRes;
        }

 

  • 解壓代碼
解壓的cmd命令:"7Z x -tzip " + zipPath + " -o" + filePath + " -y";
public ExecutionResult DeCompressFile( string zipPath, string filePath)//運(yùn)行DOS命令
        {
            ExecutionResult exeRes = new ExecutionResult();
            exeRes.Status = true;
            try
            {
                Process process = new Process();
                process.StartInfo.FileName = "cmd.exe";
                string message = "";
                string command1 = "c:";
                string command2 = @"cd\";
                string command3 = @"cd C:\Progra~1\7-Zip";
                string command4 = "";


                command4 = "7Z x -tzip " + zipPath + " -o" + filePath + " -y";

                process.StartInfo.UseShellExecute = false;
                process.StartInfo.RedirectStandardInput = true;
                process.StartInfo.RedirectStandardOutput = true;
                process.StartInfo.RedirectStandardError = true;
                process.StartInfo.CreateNoWindow = true;
                process.Start();
                process.StandardInput.WriteLine(command1);
                process.StandardInput.WriteLine(command2);
                process.StandardInput.WriteLine(command3);
                process.StandardInput.WriteLine(command4);
                process.StandardInput.WriteLine("exit");
                //process.WaitForExit();
                message = process.StandardOutput.ReadToEnd();//要等壓縮完成后才可以來抓取這個(gè)壓縮文件

                process.Close();
                if (!message.Contains("Everything is Ok"))
                {
                    exeRes.Status = false;
                    exeRes.Message = message;
                }
                else
                {
                    exeRes.Anything = filePath;
                }
            }
            catch (Exception ex)
            {
                exeRes.Message = ex.Message;
            }

            return exeRes;
        }

 

 

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約