76.6 Writing Content to a File
Writing to an open file hosted by a document provider is similar to reading with the exception that an output stream is used instead of an input stream. The following code, for example, writes text to the output stream of the storage based file referenced by the specified Uri:
try {
val pfd = contentResolver.openFileDescriptor(uri, "w")
val fileOutputStream = FileOutputStream(
pfd.fileDescriptor)
val textContent = fileText.text.toString()
fileOutputStream.write(textContent.toByteArray())
fileOutputStream.close()
pfd.close()
} catch (e: FileNotFoundException) {
e.printStackTrace()
} catch (e: IOException) {
e...