「C:\A.TXT」と「C:\A.XLS」を圧縮した『C:\A.ZIP』を作るサンプルです。J# の vjslib.dll を参照設定しておいてください。
[06/15/2004]Programming Library(VB初心者掲示板)
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim outStream As New java.util.zip.ZipOutputStream(New java.io.FileOutputStream("C:\A.ZIP"))
putFileToZip(outStream, "C:\A.TXT")
putFileToZip(outStream, "C:\A.XLS")
outStream.close()
End Sub
Private Sub putFileToZip(ByVal outStream As java.util.zip.ZipOutputStream, ByVal Path As String)
Dim size As Integer = CInt(FileLen(Path))
Dim inStream As New java.io.BufferedInputStream(New java.io.FileInputStream(Path))
Dim crc As New java.util.zip.CRC32
Dim buf(size - 1) As SByte
If inStream.read(buf, 0, size) <> -1 Then
crc.update(buf, 0, size)
outStream.write(buf, 0, size)
End If
Dim entry As New java.util.zip.ZipEntry(System.IO.Path.GetFileName(Path))
entry.setMethod(java.util.zip.ZipEntry.DEFLATED)
entry.setSize(size)
entry.setCrc(crc.getValue())
outStream.putNextEntry(entry)
inStream.close()
outStream.closeEntry()
outStream.flush()
End Sub