IBM i and Zip Files
January 11, 2012 Ted Holt
You may have heard of the new zip file APIs–QZipZip and QZipUnzip–that IBM added to IBM i 7.1. I am looking forward to using them. But if your shop is like mine, that is, you’re not running 7.1, there’s another way to work with zip files, and it does a good job. The other way is the Java Archive utility, or jar. It’s an easy command to use, and it runs under Qshell. Here’s how it works. The jar command has several parameters. First is a case-sensitive list of options. You will always need a lowercase “f” option. Second is the name of the jar or zip file. Whether you need additional parameters or not depends on the list of options. I think the best way to show you how to use jar is to provide some examples. First, here’s how to create a zip file called “files.zip” to contain files “file01.txt” and “file02.txt”. jar cfM files.zip file01.txt file02.txt Option “c” means that the archive file is being created. Option “f” means that the second parameter contains the archive filename. Option “M” tells jar not to create a manifest file. Notice that “M” is uppercase. You don’t have to know what a manifest file is. The files to be zipped are named in the third and following parameters. These file names may include wildcards. Now view the contents of the archive. jar tf files.zip Option “t” means to view the list of files in the archive. Extract the files from (unzip) the archive. jar xf files.zip Option “x” stands for “extract”. Add another file, “file03.txt”, to the archive. jar ufM files.zip file03.txt Option “u” means to update the archive. Notice option “M” again. I assume you’ll be exchanging archive files with PCs. If so, be aware that you need to create IFS files with a code page that other systems can use, such as 819 (one of the ASCII code pages). For more information about the new zip APIs, visit IBM’s announcement letter. To learn more about jar, visit the Java Archive Tool page.
|