谁有压缩和解压缩的代码 如题我要压缩一个很大的字符串 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 gzip,参考以下文章http://msdn2.microsoft.com/zh-cn/library/system.io.compression.gzipstream(VS.80).aspx public static string CompressString(string unCompressedString) { byte[] bytData = System.Text.Encoding.UTF8.GetBytes(unCompressedString); MemoryStream ms = new MemoryStream(); Stream s = null; try { s = new GZipStream(ms, CompressionMode.Compress); int totalRead = 0; int bufLen = 4096; int thisRead = 0; while (true) { if (totalRead < bytData.Length) { thisRead = bytData.Length - totalRead; if (thisRead > bufLen) thisRead = bufLen; s.Write(bytData, totalRead, thisRead); totalRead = totalRead + thisRead; } else break; } } catch (Exception e) { LogUtil.LogError("Compress String Error:" + e.Message); } finally { if (s != null) { s.Close(); s.Dispose(); s = null; } } byte[] compressedData = (byte[])ms.ToArray(); ms.Close(); ms.Dispose(); return System.Convert.ToBase64String(compressedData, 0, compressedData.Length); } 如何用C#修改第三方程序的FormBorderStyle的属性 正则表达式提取字符串 怎么在C# 绘图中禁止窗口重绘。 请用vs2005做过MMC开发的进来 初学C#,遇到的问题,数据库连接查询出错 这样的面试还有希望吗? 有没有像QQ好友上线提示那样的源码? 紧急求助!!! openFileDialog打不开 如何在添加引用中看到自己的DLL? 急求~~~~ C# 多线程编程,高手指点
http://msdn2.microsoft.com/zh-cn/library/system.io.compression.gzipstream(VS.80).aspx
{
byte[] bytData = System.Text.Encoding.UTF8.GetBytes(unCompressedString);
MemoryStream ms = new MemoryStream();
Stream s = null;
try
{
s = new GZipStream(ms, CompressionMode.Compress);
int totalRead = 0;
int bufLen = 4096;
int thisRead = 0;
while (true)
{
if (totalRead < bytData.Length)
{
thisRead = bytData.Length - totalRead;
if (thisRead > bufLen)
thisRead = bufLen;
s.Write(bytData, totalRead, thisRead);
totalRead = totalRead + thisRead;
}
else
break;
}
}
catch (Exception e)
{
LogUtil.LogError("Compress String Error:" + e.Message);
}
finally
{
if (s != null)
{
s.Close();
s.Dispose();
s = null;
}
}
byte[] compressedData = (byte[])ms.ToArray();
ms.Close();
ms.Dispose();
return System.Convert.ToBase64String(compressedData, 0, compressedData.Length); }