I found a library that can operate a ZIP file with just one line of code, so I will introduce it.
If you are familiar with Java, you probably know it, so I won't explain it in detail.
pom.xml
<!-- https://mvnrepository.com/artifact/org.zeroturnaround/zt-zip -->
<dependency>
<groupId>org.zeroturnaround</groupId>
<artifactId>zt-zip</artifactId>
<version>1.13</version>
</dependency>
build.gradle
// https://mvnrepository.com/artifact/org.zeroturnaround/zt-zip
compile group: 'org.zeroturnaround', name: 'zt-zip', version: '1.13'
Here are some codes that you will use often. Since it is implemented by the static method, you can write each in just one line.
//Unzip
ZipUtil.unpack(new File("C:/work/file.zip"), new File("C:/work/unzip/"));
//Compress
ZipUtil.pack(new File("C:/work/unzip/"), new File("C:/work/file.zip"));
//Replace the files in the ZIP
boolean successFlg = ZipUtil.replaceEntry(new File("C:/work/file.zip"),
"/config/production.properties", new File("C:/work/production.properties"));
//Add files into ZIP
ZipUtil.addEntry(new File("C:/work/file.zip"), "/config/develop.properties", new File("C:/work/develop.properties"), new File("C:/work/file_dst.zip"));
Let's see the official documentation ... Written in simple English. zeroturnaround/zt-zip: ZeroTurnaround ZIP Library
Recommended Posts