VB.net 2005内GZipStream类别可以针对档案做压缩、解压缩
Imports System.IO
Imports System.IO.Compression
Public Class ClsZip
Public Sub CompressFile(ByVal sourceFile As String, ByVal destinationFile As String)
'压缩档案
If Not File.Exists(sourceFile) Then
Throw New FileNotFoundException
End If
Dim sourceStream As FileStream = Nothing
Dim destinationStream As FileStream = Nothing
Dim compressedStream As GZipStream = Nothing
Try
'Read the bytes from the source file into a byte array
sourceStream = New FileStream(sourceFile, FileMode.Open, FileAccess.Read, FileShare.Read)
'Read the source stream values into the buffer
Dim buffer(sourceStream.Length - 1) As Byte
Dim checkCounter As Integer = sourceStream.Read(buffer, 0, buffer.Length)
If checkCounter <> buffer.Length Then
Throw New ApplicationException
End If
'Open the FileStream to write to
destinationStream = New FileStream(destinationFile, FileMode.OpenOrCreate, FileAccess.Write)
'Create a compression stream pointing to the destiantion stream
compressedStream = New GZipStream(destinationStream, CompressionMode.Compress, True)
'Now write the compressed data to the destina ..
访客只能看到部份内容,免费 加入会员 或由脸书 Google 可以看到全部内容