Create file ZIP in Kotlin

后端 未结 4 1164
别跟我提以往
别跟我提以往 2020-12-31 05:28

I\'m trying to create a zip file in Kotlin. this is the code:

fun main(args: Array) {
var files: Array = arrayOf(\"/home/matte/th         


        
4条回答
  •  旧时难觅i
    2020-12-31 06:27

    If you use Kotlin's IOStreams.copyTo() extension, it will do the copying work for you, and that ended up working for me.

    So replace this:

    origin.buffered(1024).reader().forEachLine {
        out.write(data)
    }
    

    With this:

    origin.copyTo(out, 1024)
    

    I also had issues with the ZipEntry having a leading slash, but that could just be because I'm on Windows.

    Note: I didn't end up needing to call closeEntry() to get this to work but it is recommended.

提交回复
热议问题