0
壓縮工作得很好,還有解壓縮,但是如果應用程序在String被壓縮後直接關閉了,我該怎麼辦?我怎樣才能解壓它只有字符串?我如何使用GZip解壓字符串?
//Compress
Dim mem As New IO.MemoryStream
Dim gz As New System.IO.Compression.GZipStream(mem, IO.Compression.CompressionMode.Compress)
Dim sw As New IO.StreamWriter(gz)
sw.WriteLine("hello compression")
sw.Close()
Dim compressed As String = Convert.ToBase64String(mem.ToArray())
//Decompress
Dim mem2 As New IO.MemoryStream(mem.ToArray)
gz = New System.IO.Compression.GZipStream(mem2, IO.Compression.CompressionMode.Decompress)
Dim sr As New IO.StreamReader(gz)
MsgBox(sr.ReadLine)
sr.Close()
Dim decompressed As String = sr.ReadLine()
好的,butw我該怎麼做?我在編碼方面很新穎... –
Google是你的朋友。 StackOverflow用於解決人們在代碼中遇到的問題。不幸的是,它不是教程網站。我發現這個網站向你展示瞭如何將內存流保存到文件。 http://net-informations.com/q/faq/memory.html –
非常感謝! –