core-ktx / androidx.util / android.util.AtomicFile

Extensions for android.util.AtomicFile

readBytes

fun AtomicFile.readBytes(): ByteArray

Gets the entire content of this file as a byte array.

readText

fun AtomicFile.readText(charset: Charset = Charsets.UTF_8): String

Gets the entire content of this file as a String using UTF-8 or specified charset.

tryWrite

fun AtomicFile.tryWrite(block: (out: FileOutputStream) -> Unit): Unit

Perform the write operations inside block on this file. If block throws an exception the write will be failed. Otherwise the write will be applied atomically to the file.

writeBytes

fun AtomicFile.writeBytes(array: ByteArray): Unit

Sets the content of this file as an array of bytes.

writeText

fun AtomicFile.writeText(text: String, charset: Charset = Charsets.UTF_8): Unit

Sets the content of this file as text encoded using UTF-8 or specified charset. If this file exists, it becomes overwritten.