Imports System.IO Imports java.io 'C:/WINNT/Microsoft.NET/Framework/v2.0.50727/vjslib.dll Imports java.util ''' <summary> ''' 解压(Zip) ''' </summary> ''' <param name="ZipFile">需要解压的ZIP文件</param> ''' <param name="OutputDirectory">输入目录</param> ''' <remarks>2010-01-30</remarks> Private Shared Sub Decompress(ByVal ZipFile As String,ByVal OutputDirectory As String) Dim zipIns As New java.io.File(ZipFile) Dim directoryIns As New java.io.File(OutputDirectory) '判断压缩文件是否存在 '如果不存在的场合,则退出 If zipIns.exists = False Then Return End If zipIns = Nothing '判断输出目录是否是目录 '如果不是目录的场合,再进行其它判断 If directoryIns.isDirectory = False Then '判断输出目录的类型是否是一个文件 '如果不是文件的场合 If directoryIns.isFile = False Then Directory.CreateDirectory(OutputDirectory) '如果输出目录是一个存在的文件的场合,则退出 Else Return End If End If directoryIns = Nothing Const BUFFER As Integer = 2048 '每次读取文件数据的大小 Dim fileInput As FileInputStream '文件流 Dim inputStream As zip.ZipInputStream '输入流 Dim entry As zip.ZipEntry '压缩数据入口实例 Dim outputStream As FileOutputStream '输出流 Dim outputDir As String '输出目录 Dim fileName As String '文件名 Dim folderSeparator As String '文件夹分隔符 Dim folderSeparatorInZipFile As String '压缩文件中的文件夹分隔符 Dim dataCount As Integer '数据总数 Dim fileData(BUFFER) As SByte '用于存放已读取的文件数据 '取得文件夹分隔符 folderSeparator = java.io.File.separator folderSeparatorInZipFile = "/" '判断输出目录是否是一个完整的目录 '如果不是的场合,则编辑 outputDir = OutputDirectory If outputDir.Substring(outputDir.Length - 1,1) <> folderSeparator Then outputDir += folderSeparator End If '初始化压缩文件输入流 fileInput = New FileInputStream(ZipFile) inputStream = New zip.ZipInputStream(New BufferedInputStream(fileInput)) '循环解压压缩文件中每个文件 Do '取得下一个压缩数据的入口 entry = inputStream.getNextEntry() If entry Is Nothing Then Exit Do End If '判断当前压缩数据是文件还是文件夹 '如果是文件的场合 If entry.isDirectory = False Then '取得文件名 fileName = entry.getName() fileName = fileName.Substring(fileName.LastIndexOf(folderSeparator) + 1) '如果是文件夹的场合 Else '创建新文件夹 fileName = entry.getName() fileName = fileName.Replace(folderSeparator,folderSeparatorInZipFile) Directory.CreateDirectory(outputDir + fileName) Continue Do End If outputStream = New java.io.FileOutputStream(outputDir & fileName) '初始化取数据用的变量 Array.Clear(fileData,fileData.Length) dataCount = 0 '循环读取当前需要解压的文件数据 Do '读取文件数据 dataCount = inputStream.read(fileData,BUFFER) If dataCount = -1 Then Exit Do End If '将已读取的文件数据写入输出目录中 outputStream.write(fileData,dataCount) Loop '关闭输出流 outputStream.flush() outputStream.close() Loop '关闭输入流和文件流 inputStream.closeEntry() inputStream.close() fileInput.close() End Sub