Skip to content

Instantly share code, notes, and snippets.

@tdcolvin
Created February 3, 2023 18:44
Show Gist options
  • Save tdcolvin/542d302a8102c6bcaeb0cdc887de7883 to your computer and use it in GitHub Desktop.
Save tdcolvin/542d302a8102c6bcaeb0cdc887de7883 to your computer and use it in GitHub Desktop.
fun writeToEncryptedFile(content: String) {
//Open the file for writing, and write our contents to it.
//Note how Kotlin's 'use' function correctly closes the resource after we've finished,
//regardless of whether or not an exception was thrown.
encryptedFile.openFileOutput().use {
it.write(content.toByteArray(StandardCharsets.UTF_8))
it.flush()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment