Zip壓縮工具

建立簡單壓縮,可設定幾筆檔案包成一包與名稱策略

@Test
void testZip() throws URISyntaxException {

    ClassLoader classLoader = ZipServiceTest.class.getClassLoader();
    URL resource1 = classLoader.getResource("file1.txt");
    URL resource2 = classLoader.getResource("file2.txt");

    List<File> files = Arrays.asList(//
            new File(resource1.toURI()), //
            new File(resource2.toURI()));//

    ZipMakeOption option = new ZipMakeOption(this::getFileName, 1, "/ZIP");
    option.addAllFile(files);
    option.setMakeZipListener(file -> log.info("ok file size:{}", file.size()));
    List<File> makeZip = zipService.makeZip(option);
    assertThat(makeZip).isNotEmpty();
}
<dependency>
  <groupId>io.github.h8000572003</groupId>
  <artifactId>zip</artifactId>
  <version>0.0.1</version>
</dependency>

Last updated

Was this helpful?