import java.io.IOException; import java.io.RandomAccessFile; import net.sf.sevenzipjbinding.IInArchive; import net.sf.sevenzipjbinding.PropID; import net.sf.sevenzipjbinding.SevenZip; import net.sf.sevenzipjbinding.SevenZipException; import net.sf.sevenzipjbinding.impl.RandomAccessFileInStream; public class ListItemsStandard { public static void main(String[] args) { if (args.length == 0) { System.out.println("Usage: java ListItemsStandard <archive-name>"); return; } RandomAccessFile randomAccessFile = null; IInArchive inArchive = null; try { randomAccessFile = new RandomAccessFile(args[0], "r"); inArchive = SevenZip.openInArchive(null, // autodetect archive type new RandomAccessFileInStream(randomAccessFile)); System.out.println(" Size | Compr.Sz. | Filename"); System.out.println("----------+-----------+---------"); int itemCount = inArchive.getNumberOfItems(); for (int i = 0; i < itemCount; i++) { System.out.println(String.format("%9s | %9s | %s", // inArchive.getProperty(i, PropID.SIZE), inArchive.getProperty(i, PropID.PACKED_SIZE), inArchive.getProperty(i, PropID.PATH))); } } catch (Exception e) { System.err.println("Error occurs: " + e); } finally { if (inArchive != null) { try { inArchive.close(); } catch (SevenZipException e) { System.err.println("Error closing archive: " + e); } } if (randomAccessFile != null) { try { randomAccessFile.close(); } catch (IOException e) { System.err.println("Error closing file: " + e); } } } } }