unzip an archive using java in matlab

Assuming you have a zip archive called "archive.zip", and you want to extract its contents in the same directory:

main.m
% Create a java File object from the archive path
zipFile = java.io.File('archive.zip');

% Create a java ZipFile object from the File
zip = org.apache.tools.zip.ZipFile(zipFile);

% Extract all archive contents in the same directory
zip.extractAll(pwd);
255 chars
9 lines

Note that the password (pwd) parameter is optional and refers to the password of the zip archive, if there is any. If not, you can omit it:

main.m
zip.extractAll();
18 chars
2 lines

Also, make sure that the "ant.jar" and "ant-launcher.jar" files, which are used by the "org.apache.tools.zip.ZipFile" class, are present in the Java classpath. You can add them using javaaddpath command:

main.m
javaaddpath('path/to/ant.jar');
javaaddpath('path/to/ant-launcher.jar');
73 chars
3 lines

related categories

gistlibby LogSnag