扣丁书屋

Kotlin 读取文件流的写法

2年以前  |  阅读数:187 次  |    

fun copyFileTest() {
    val oldFile = File("E:SQLFULL_CHS.iso")
    val newFile = File("E:SQLFULL_CHS2.iso")
    newFile.deleteOnExit()
    newFile.createNewFile()
    var c = -1
    val buffer = ByteArray(1024 * 1000)
    val inputStream = oldFile.inputStream()
    val now = System.currentTimeMillis()
    while ({ c = inputStream.read(buffer);c }() > 0) {
        newFile.appendBytes(buffer.copyOfRange(0, c))
    }
    println("复制完毕,耗时${(System.currentTimeMillis() - now) / 1000}秒")
}

相关文章: