| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1065 人关注过本帖
标题:GZipStream类的用法
只看楼主 加入收藏
tntzwc
Rank: 3Rank: 3
等 级:新手上路
威 望:7
帖 子:216
专家分:0
注 册:2007-4-28
收藏
 问题点数:0 回复次数:3 
GZipStream类的用法
GZipStream类的资料
搜索更多相关主题的帖子: GZipStream 用法 
2007-07-26 15:00
tntzwc
Rank: 3Rank: 3
等 级:新手上路
威 望:7
帖 子:216
专家分:0
注 册:2007-4-28
收藏
得分:0 

不是吧,没有人知道。
看来只有我自己研究了。


努力了有可能失败,不努力一定失败!
2007-07-27 12:08
tntzwc
Rank: 3Rank: 3
等 级:新手上路
威 望:7
帖 子:216
专家分:0
注 册:2007-4-28
收藏
得分:0 

找不到头绪。
请问有没有哪位大哥用过?
可以给小弟讲一下吗?


努力了有可能失败,不努力一定失败!
2007-07-27 12:54
tntzwc
Rank: 3Rank: 3
等 级:新手上路
威 望:7
帖 子:216
专家分:0
注 册:2007-4-28
收藏
得分:0 

好像在压缩文件的时候有问题。
不过压缩字符串还是不错的,好像是字符串的可逆加密。

大家可以看看。

using System;
using System.Collections.Generic;
using System.Text;
using System.IO.Compression;
using System.IO;

namespace ConsoleApplication4
{
class Program
{

//压缩字符串


private static string zipStrFunction(string zipstr)
{
byte[] btdata = System.Text.UTF8Encoding.UTF8.GetBytes(zipstr);
MemoryStream ms = new MemoryStream();
Stream s = new GZipStream(ms, CompressionMode.Compress);
s.Write(btdata, 0, btdata.Length);
s.Close();
byte[] compressedData = (byte[])ms.ToArray();
return System.Convert.ToBase64String(compressedData, 0, compressedData.Length);
}

//解压缩字符串

public static string unzipFunction(string unzipstr)
{
System.Text.StringBuilder uncompressedString = new System.Text.StringBuilder();
byte[] writeData = new byte[4096];

byte[] bytData = System.Convert.FromBase64String(unzipstr);

int size = 0;
MemoryStream ms = new MemoryStream(bytData);
GZipStream zipstream = new GZipStream(ms, CompressionMode.Decompress);
while ((size = zipstream.Read(writeData, 0, writeData.Length))>0)
{
uncompressedString.Append(System.Text.Encoding.UTF8.GetString(writeData, 0, size));
}
zipstream.Close();
return uncompressedString.ToString();
}

public static void Main(string[] args)
{
string zipStr, compressedStr,uncompressedStr;
Console.WriteLine("输入要压缩的字符串");
zipStr = Console.ReadLine();
compressedStr = zipStrFunction(zipStr);
Console.WriteLine("压缩后的:");
Console.WriteLine(compressedStr);

Console.WriteLine("解压:");
uncompressedStr = unzipFunction(compressedStr);
Console.WriteLine(uncompressedStr);

Console.ReadLine();
}
}
}


努力了有可能失败,不努力一定失败!
2007-07-27 14:22
快速回复:GZipStream类的用法
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.019371 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved