Last active
February 3, 2023 18:56
-
-
Save tdcolvin/9532270acffd5a5f1aa4a06803fae0b4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun readFromEncryptedFile(): String { | |
//We will read up to the first 32KB from this file. If your file may be larger, then you | |
//can increase this value, or read it in chunks. | |
val fileContent = ByteArray(32000) | |
//The number of bytes actually read from the file. | |
val numBytesRead: Int | |
//Open the file for reading, and read all the contents. | |
//Note how Kotlin's 'use' function correctly closes the resource after we've finished, | |
//regardless of whether or not an exception was thrown. | |
encryptedFile.openFileInput().use { | |
numBytesRead = it.read(fileContent) | |
} | |
return String(fileContent, 0, numBytesRead) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment