已有56人关注
C#数据库系统开发案例精选--库存管理系统中的数据压缩模块
发表在C#图书答疑 2009-02-25
是否精华
版块置顶:
压缩方法
public void compressFile(string M_str_DFile, string M_str_CFile)
        {
            if (!File.Exists(M_str_DFile)) throw new FileNotFoundException();
            using (FileStream sourceStream = new FileStream(M_str_DFile, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite))
            {
                byte[] buffer = new byte[sourceStream.Length];
                int checkCounter = sourceStream.Read(buffer, 0, buffer.Length);
                if (checkCounter != buffer.Length) throw new ApplicationException();
                using (FileStream destinationStream = new FileStream(M_str_CFile, FileMode.OpenOrCreate, FileAccess.Write))
                {
                    using (GZipStream compressedStream = new GZipStream(destinationStream, CompressionMode.Compress, true))
                    {
                        compressedStream.Write(buffer, 0, buffer.Length);
                    }
                }
            }
        }

button 事件
 private void btnFCut_Click(object sender, EventArgs e)
        {
            try
            {
                doperate.compressFile(txtFile.Text.Trim(), txtDCPath.Text.Trim() + ".rar");
                MessageBox.Show("文件压缩成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            btnDCut.Enabled = true;
            txtDCPath.ReadOnly = true;
            btnFCut.Enabled = false;
        }

问题:
    为什么单击文件压缩按纽后压缩的压缩文件 再解压缩后还原的文件不可识别(例如把.txt文件压缩后再解压缩系统不显示是.txt文件) 麻烦明日的软件工程师们帮我解决一下 ,谢谢!
顺便问一下 在项目里引用sharpziplib.dll也能压缩 压缩解压怎么写 怎么引用sharpziplib.dll 我怎么在项目里找不到sharpziplib.dll
分享到:
精彩评论 1
小科_mrkj
学分:43 LV2
2009-02-25
沙发
读者朋友:
    您好,解压缩时需要指定文件扩展名。
    sharpziplib.dll是一个第3方组件,需要到网上下载,然后在程序中通过添加引用,找到sharpziplib.dll即可。
首页上一页 1 下一页尾页 1 条记录 1/1页
手机同步功能介绍
友情提示:以下图书配套资源能够实现手机同步功能
明日微信公众号
明日之星 明日之星编程特训营
客服热线(每日9:00-17:00)
400 675 1066
mingrisoft@mingrisoft.com
吉林省明日科技有限公司Copyright ©2007-2022,mingrisoft.com, All Rights Reserved长春市北湖科技开发区盛北大街3333号长春北湖科技园项目一期A10号楼四、五层
吉ICP备10002740号-2吉公网安备22010202000132经营性网站备案信息 营业执照