title: Saving file in internal storage using Uri (obtained from Storage Access network)
body: <p>I'm using Storage Access Network to pick file and save in internal storage so that app can use if in future.</p>
  
  <p>I'm getting URI without any issues. It's something like content://com.android.providers.media.documents/document/image%3A141274</p>
  
  <p>Problem comes when I'm trying to save image into internal directory. Code passes without crashes, image with same size is saved into internal directory (I can see it in device Explorer: <a href="https://take.ms/3TwBS" rel="nofollow noreferrer">https://take.ms/3TwBS</a>).
  But image itself is broken and can't be opened. </p>
  
  <p>Here's code I'm using (after getting URI)</p>
  
  <pre><code>val destinationFile = File("${context.filesDir.absolutePath}/$fileName")
  try {
                          val writer = FileWriter(destinationFile)
                          writer.append(readTextFromUri(it))
                          writer.flush()
                          writer.close()
  
                      } catch (e: Exception) {
                          e.printStackTrace()
  
                      }
  
  
   @Throws(IOException::class)
      private fun readTextFromUri(uri: Uri): String {
          val inputStream = activity!!.contentResolver.openInputStream(uri)
          val reader = BufferedReader(InputStreamReader(inputStream))
          val stringBuilder = StringBuilder()
          var line: String? = null
          while ({ line = reader.readLine(); line }() != null) {
              stringBuilder.append(line)
          }
          inputStream?.close()
          reader.close()
          return stringBuilder.toString()
      }
  </code></pre>