最近碰到好多人不会kotlin中io流的while循环条件语句怎么写,直接上代码吧。。。
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}秒")
}
复制代码
现在的孩子,哎。。。