I wrote this simple program is for my daily backup purpose. With this program I can compress the folder into a zip file and save to my backup folder.
1. Add reference: .NET ---> VJSLIB

2. Imports NameSpace:
Imports java.util.zip
Imports java.util
Imports java.io
3. Call Java function to Compress files and extract zip file
A: Compress to Zip File
Public Function ZipFiles(ByVal zipFileName As String, ByVal sourceRootPath As String, ByVal sourceFiles As System.Collections.ArrayList) As Boolean
ZipFiles = False
Try
Dim objFileOutStream As New FileOutputStream(zipFileName)
Dim objZipOutStream As New ZipOutputStream(objFileOutStream)
Dim objFileInStream As FileInputStream = Nothing
Dim ze As ZipEntry
Dim len As Integer
Dim fileCount = sourceFiles.Count - 1
Dim fileName As String
For i As Integer = 0 To fileCount
fileName = sourceFiles(i)
objFileInStream = New FileInputStream(fileName)
ze = New ZipEntry(fileName.Replace(sourceRootPath, String.Empty).Substring(1))
objZipOutStream.putNextEntry(ze)
Dim buffer(1024) As SByte
len = 0
len = objFileInStream.read(buffer)
While len >= 0
objZipOutStream.write(buffer, 0, len)
len = objFileInStream.read(buffer)
End While
Next
objZipOutStream.closeEntry()
objFileInStream.close()
objZipOutStream.close()
objFileOutStream.close()
ZipFiles = True
Catch ex As Exception
Me._expObj = ex
End Try
End Function
B: Extract ZIp File
Public Function Extract(ByVal sourceZipFile As String, ByVal destinationPath As String) As Boolean
Extract = False
Try
Dim zipfile As New ZipFile(sourceZipFile)
Dim zeList As List(Of ZipEntry) = Me.GetAllZipEntries(zipfile)
Dim dirPath As String
Dim len As Integer
For Each ze As ZipEntry In zeList
If Not ze.isDirectory Then
Dim s As InputStream = zipfile.getInputStream(ze)
Try
dirPath = Path.Combine(destinationPath, Path.GetDirectoryName(ze.getName))
System.IO.Directory.CreateDirectory(dirPath)
Dim dest As New FileOutputStream(Path.Combine(dirPath, Path.GetFileName(ze.getName)))
Try
len = 0
Dim buffer(7168) As SByte
len = s.read(buffer)
While len >= 0
dest.write(buffer, 0, len)
len = s.read(buffer)
End While
Catch ex As Exception
Me._expObj = ex
Exit Function
Finally
dest.close()
End Try
Catch ex As Exception
Me._expObj = ex
Exit Function
Finally
s.close()
End Try
End If
Next
Extract = True
Catch ex As Exception
Me._expObj = ex
End Try
End Function
Download Source Code and Demo Project : Password: www.hczhu.com