Net压缩文件流
来源:未知 责任编辑:责任编辑 发表时间:2013-11-17 14:39 点击:次
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO.Compression;
using System.IO;
namespace gzipfile
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
//文件流
FileStream reader;
reader = File.Open("D:\\ddd.txt", FileMode.Open);
FileStream writer;
writer = File.Create("D:\\ddd.gz");
//压缩相关的流
MemoryStream ms = new MemoryStream();
GZipStream zipStream = new GZipStream(ms, CompressionMode.Compress, true);
//往压缩流中写数据
byte[] sourceBuffer = new byte[reader.Length];
reader.Read(sourceBuffer, 0, sourceBuffer.Length);
zipStream.Write(sourceBuffer, 0, sourceBuffer.Length);
//一定要在内存流读取之前关闭压缩流
zipStream.Close();
zipStream.Dispose();
//从内存流中读数据
ms.Position = 0; //注意,不要遗漏此句
byte[] destBuffer = new byte[ms.Length];
//ms.Read(destBuffer, 0, destBuffer.Length);
byte[] header = new byte [10];
ms.Read(header, 0, 10);
header[3] = 8; //表示包含文件名信息
byte[] fielContent = new byte[ms.Length -10] ;
ms.Read(fielContent, 0, fielContent.Length);
string strfilename = "widebright的文件.txt"; //指定初始文件名
//byte [] filename=System.Text.Encoding.Convert(System.Text.Encoding.Default,
// // System.Text.Encoding.GetEncoding("ISO-8859-1"),
// System.Text.Encoding.Default,
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO.Compression;
using System.IO;
namespace gzipfile
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
//文件流
FileStream reader;
reader = File.Open("D:\\ddd.txt", FileMode.Open);
FileStream writer;
writer = File.Create("D:\\ddd.gz");
//压缩相关的流
MemoryStream ms = new MemoryStream();
GZipStream zipStream = new GZipStream(ms, CompressionMode.Compress, true);
//往压缩流中写数据
byte[] sourceBuffer = new byte[reader.Length];
reader.Read(sourceBuffer, 0, sourceBuffer.Length);
zipStream.Write(sourceBuffer, 0, sourceBuffer.Length);
//一定要在内存流读取之前关闭压缩流
zipStream.Close();
zipStream.Dispose();
//从内存流中读数据
ms.Position = 0; //注意,不要遗漏此句
byte[] destBuffer = new byte[ms.Length];
//ms.Read(destBuffer, 0, destBuffer.Length);
byte[] header = new byte [10];
ms.Read(header, 0, 10);
header[3] = 8; //表示包含文件名信息
byte[] fielContent = new byte[ms.Length -10] ;
ms.Read(fielContent, 0, fielContent.Length);
string strfilename = "widebright的文件.txt"; //指定初始文件名
//byte [] filename=System.Text.Encoding.Convert(System.Text.Encoding.Default,
// // System.Text.Encoding.GetEncoding("ISO-8859-1"),
// System.Text.Encoding.Default,
相关新闻>>
最新推荐更多>>>
- 发表评论
-
- 最新评论 更多>>
今日头条
更多>>您可能感兴趣的文章
- ASP.NET Web Page应用深入探讨第1/2页
- wcf系列5天速成——第二天 binding的使用(2)
- asp.net 中将表单提交到另一页 Code-Behind的代码实现
- .net 网站开发维护基础知识
- 微软.NET 常见问题解答(1)
- .NET中的DRY和SHY原则
- asp.net 枚举文件里面的数字绑定到DropDownList里面去
- .net第三方插件Infragistics中的UltraWebTab控件,切换tab页的on
- 如何在ASP.NET MVC中使用图表控件
- the sourcesafe database has been locked by the administrator