编程语言
首页 > 编程语言> > kotlin(java) 文件压缩

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

标签:java,sevenZOutput,kotlin,压缩,compress,commons,path,org
来源: https://blog.csdn.net/summer_sama/article/details/123225263