用SharpZipLib 解压zip文件的中文文件名的问题
如题,最近在使用sharpziplib解压zip文件(包含多个文件),解压后中文文件名显示都是 ?????,网上好多的方法都是在java下的,.net 下的方法怎么处理,几乎没有。希望做过的朋友帮帮忙,谢谢了。
[解决办法]
- VB.NET code
''' <summary> ''' 解压缩文件(压缩文件中含有子目录) ''' </summary> ''' <param name="ZipFilePath">待解压缩的文件路径</param> ''' <param name="SavePath">解压缩到指定目录</param> Public Sub UnZip(ByVal ZipFilePath As String, ByVal SavePath As String) Dim s As New ZipInputStream(File.OpenRead(ZipFilePath)) Dim theEntry As ZipEntry ' C# while ((theEntry = s.GetNextEntry()) != null) While (InlineAssignHelper(theEntry, s.GetNextEntry())) IsNot Nothing Dim directoryName As String = Path.GetDirectoryName(SavePath) Dim fileName As String = Path.GetFileName(theEntry.Name) '生成解压目录 Directory.CreateDirectory(directoryName) If String.IsNullOrEmpty(fileName) = False Then '如果文件的压缩后大小为0那么说明这个文件是空的,因此不需要进行读出写入 If theEntry.CompressedSize = 0 Then Exit While End If '解压文件到指定的目录 directoryName = Path.GetDirectoryName(SavePath & theEntry.Name) '建立下面的目录和子目录 Directory.CreateDirectory(directoryName) Dim streamWriter As FileStream = File.Create(SavePath & theEntry.Name) Dim size As Integer = 2048 Dim data As Byte() = New Byte(2047) {} While True size = s.Read(data, 0, data.Length) If size > 0 Then streamWriter.Write(data, 0, size) Else Exit While End If End While streamWriter.Close() End If End While s.Close() End Sub Private Shared Function InlineAssignHelper(Of T)(ByRef target As T, ByVal value As T) As T target = value Return value End Function