kotlin(java) 文件压缩

kotlin 7z 多文件压缩

kotlin:

	/**
	* list 需要压缩的文件集合,
	* path 压缩到的文件 例如 File("/home/app/compress.7z").toPath()
	*/
    fun compressFileTo7z(list:List<File>,path:Path){
        val sevenZOutput = SevenZOutputFile(path.toFile())
        list.forEach{
            val entry: SevenZArchiveEntry = sevenZOutput.createArchiveEntry(it.toPath(), it.name)
            sevenZOutput.putArchiveEntry(entry);
            sevenZOutput.write(Files.newInputStream(it.toPath()).readAllBytes())
            sevenZOutput.closeArchiveEntry();
        }
        sevenZOutput.close()
        log.info("compress over")
    }

使用依赖(gradle(kotlin))

  // https://mvnrepository.com/artifact/org.apache.commons/commons-compress
	implementation("org.apache.commons:commons-compress:1.21")
	// https://mvnrepository.com/artifact/org.tukaani/xz
	implementation("org.tukaani:xz:1.9")

gradle + kotlin + jdk17
more in lolidate

你可能感兴趣的:(kotlin,java,kotlin,gradle)