using Telerik.Windows.Zip; /// <summary> /// 利用telerik的zip库压缩字符串 /// </summary> /// <param name="str"></param> /// <returns></returns> public static string CompressString(string str) { string result = string.Empty; try { var memoryStream = new MemoryStream(); var zipOutputStream = new ZipOutputStream(memoryStream, ZipCompression.Default); var writer = new StreamWriter(zipOutputStream); writer.Write(str); writer.Flush(); result = Convert.ToBase64String(memoryStream.ToArray()); } catch { } return result; } /// <summary> /// 利用telerik的zip库解压字符串 /// </summary> /// <param name="compressedBase64String"></param> /// <returns></returns> public static string UnCompressString(string compressedBase64String) { string result = string.Empty; try { var memoryStream = new MemoryStream(Convert.FromBase64String(compressedBase64String)); var input = new ZipInputStream(memoryStream); var reader = new StreamReader(input); result = reader.ReadToEnd(); } catch { } return result; }
转载于:https://www.cnblogs.com/ncore/archive/2012/11/12/2766656.html
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/110283.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...