Travis Tran

Travis Tran

Keep Doing Better

Compressor4j

Java dependency to simplify process of compressing and decompressing files and folders.

Compressor4j is a Java dependency to simplify process of compressing and decompressing files and folders.

  • Support compressing for file types: ZIP, GZ, TAR, TAR.GZ, JAR, BZ2, TAR.BZ2, AR, CPIO, XZ.
  • Support decompressing for file types: ZIP, GZ, TAR, TAR.GZ, JAR, BZ2, TAR.BZ2, AR, CPIO, 7Z, XZ, RAR.
  • JRE support: 7+

Compress files or folders

To compress files or folders, you could use as the following example:

public static void write() throws Exception {
	try {
		FileCompressor fileCompressor = new FileCompressor();
		String[] files = new String[] { "IMG_01.JPG", "/02/IMG_02.JPG", "/03/IMG_03.JPG" };
		for (String file : files) {
			fileCompressor.add(SRC_PATH + file, file);
		}
		fileCompressor.setType(CompressionType.JAR);
		fileCompressor.setLevel(ZipLevel.NORMAL);
		fileCompressor.setCompressedPath("output.jar");
		fileCompressor.compress();
	} catch (Exception e) {
		e.printStackTrace();
	}
}

Extract compressed file

To decompress files or folders, you could use as the following example:

public static void read() throws Exception {
	try {
		FileCompressor fileCompressor = FileCompressor.read("input.zip");
		fileCompressor.decompress("output/");
	} catch (Exception e) {
		e.printStackTrace();
	}
}

For more information and usages, please visit source code repository: https://github.com/travistran1989/compressor4j

X
Welcome to travistran.me
Welcome to TravisBot
wpChatIcon