C#做ZIP压缩软件(讨论) http://msdn.microsoft.com/zh-cn/library/system.io.compression.gzipstream(VS.80).aspx 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 //转贴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);} 这个很详细http://dobon.net/vb/dotnet/links/createzipfile.html GZipStream只对文本中重复的字符压缩,二进制不压缩,没啥大的作用 C#窗体中如何自动更换某一个图案? c#实现文件预览(ai,plt,dxf) 飞信二次开发和连接移动短信网关问题(在线等)? [求助]如何获取公网IP? ADO 连接问题 有关mapx地图与数据库联接 控件数组问题 求个解决思路? socket实现winform中统计在线人数 cdma中文短信编码,请有cdma经验的指点一二(高分求助,如能解决问题可再送分) 怎么样在Form2中用Form1中的控件? 菜鸟问控制台程序..
//转贴
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);
}