W3cubDocs

/Kotlin

forEachBlock

fun File.forEachBlock(
    action: (buffer: ByteArray, bytesRead: Int) -> Unit)

Platform and version requirements: JVM

Reads file by byte blocks and calls action for each block read. Block has default size which is implementation-dependent. This functions passes the byte array and amount of bytes in the array to the action function.

You can use this function for huge files.

Parameters

action - function to process file blocks.

fun File.forEachBlock(
    blockSize: Int, 
    action: (buffer: ByteArray, bytesRead: Int) -> Unit)

Platform and version requirements: JVM

Reads file by byte blocks and calls action for each block read. This functions passes the byte array and amount of bytes in the array to the action function.

You can use this function for huge files.

Parameters

action - function to process file blocks.

blockSize - size of a block, replaced by 512 if it's less, 4096 by default.

© 2010–2017 JetBrains s.r.o.
Licensed under the Apache License, Version 2.0.
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.io/java.io.-file/for-each-block.html