为什么压缩后文件反而变大了?
代码如下:
Public Function ZipTo(ByVal strSourceFileName As String, ByVal strZipFileName As String) As Boolean
'参数: strSourceFileName 要被压缩的文件
'参数: strZipFileName 要压缩的ZIP文件,如果要压缩多个文件时,将使用第一个ZIP文件名称,如果 文件已存在 则覆盖此文件
'参数 ContinueZipFile 是否要继续压缩文件
Dim InFile As FileStream = Nothing
Dim OutFile As FileStream = Nothing
Dim Zip As Compression.GZipStream = Nothing
Dim errflag As Boolean = False '错误标志
Try
InFile = New FileStream(strSourceFileName, FileMode.Open, FileAccess.Read, FileShare.Read)
OutFile = New FileStream(strZipFileName, FileMode.Create, FileAccess.Write)
Zip = New Compression.GZipStream(OutFile, Compression.CompressionMode.Compress, True)
Dim buffer(CInt(InFile.Length - 1)) As Byte '读取字节缓冲区
Dim ReadCountByte As Integer '每次从文件中读取的字节数
ReadCountByte = InFile.Read(buffer, 0, buffer.Length)
Zip.Write(buffer, 0, buffer.Length)
Catch ex As Exception
MsgBox(ex.Message)
errflag = True
Finally
If Not InFile Is Nothing Then
InFile.Close()
InFile.Dispose()
InFile = Nothing
End If
If Not Zip Is Nothing Then
Zip.Close()
Zip.Dispose()
Zip = Nothing
End If
If Not OutFile Is Nothing Then
OutFile.Close()
OutFile.Dispose()
OutFile = Nothing
End If
End Try
Return Not errflag
End Function