我需要壓縮和解壓縮串壓縮和解壓字符串減縮
這裏是代碼:
public static byte[] ZipStr(String str)
{
using (MemoryStream output = new MemoryStream())
using (DeflateStream gzip = new DeflateStream(output, CompressionMode.Compress))
using (StreamWriter writer = new StreamWriter(gzip))
{
writer.Write(str);
return output.ToArray();
}
}
和
public static string UnZipStr(byte[] input)
{
using (MemoryStream inputStream = new MemoryStream(input))
using (DeflateStream gzip = new DeflateStream(inputStream, CompressionMode.Decompress))
using (StreamReader reader = new StreamReader(gzip))
{
reader.ReadToEnd();
return System.Text.Encoding.UTF8.GetString(inputStream.ToArray());
}
}
似乎存在UnZipStr方法錯誤。有人能幫助我嗎?
你得到一個編譯器錯誤,或異常,還是什麼?你能提供關於「錯誤」的更多細節嗎? – Nick 2010-01-22 16:59:13