W3cubDocs

/Kotlin

forEachBlock

Platform and version requirements: JVM (1.0)
fun File.forEachBlock(
    action: (buffer: ByteArray, bytesRead: Int) -> Unit)

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.

Platform and version requirements: JVM (1.0)
fun File.forEachBlock(
    blockSize: Int, 
    action: (buffer: ByteArray, bytesRead: Int) -> Unit)

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–2020 JetBrains s.r.o. and Kotlin Programming Language contributors
Licensed under the Apache License, Version 2.0.
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.io/java.io.-file/for-each-block.html