首页上一页 1 下一页尾页 1 条记录 1/1页
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
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