Class Zip

java.lang.Object
ca.spatial.util.Zip

public class Zip extends Object
A simple zip file writer. This class provides a means to write files and directories to Zip files.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Zip​(String filename)
    Create an output Zip file of the specified name
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    add​(String name)
    Write an entry to the Zip file.
    void
    add​(String parent, String name)
    Write an entry to the Zip file.
    void
    Close the Zip file.
    static void
    main​(String[] args)
    Create a zip file.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Zip

      public Zip(String filename) throws IOException
      Create an output Zip file of the specified name
      Parameters:
      filename - the name of the output zip file to create
      Throws:
      IOException - if an error occurs while creating the output file
  • Method Details

    • add

      public void add(String name) throws IOException
      Write an entry to the Zip file. If this is a directory it will be recursively added.
      Parameters:
      name - The name of the file to add.
      Throws:
      IOException - if an error occurs while adding the element
    • add

      public void add(String parent, String name) throws IOException
      Write an entry to the Zip file. If this is a directory it will be recursively added. Change directory to 'parent' before adding files.
      Parameters:
      parent - the parent file name
      name - the file name to add
      Throws:
      IOException - if an error occurs while adding the element
    • close

      public void close() throws IOException
      Close the Zip file.
      Throws:
      IOException - if an error occurs while adding the element
    • main

      public static void main(String[] args)
      Create a zip file. The first argument is the the name of the Zip archive. Subsequent arguments are the names of the files to be included in the archive.
      Parameters:
      args - the arguments to pass in to the program.