title: download pdf from server using retrofit
body: <p>i have a problem with download pdf file from server, i found function which converte byte array, i am using android 10 xiaomi mi 9.</p>
  <pre><code>    private fun InputStream.saveToFile(file: String) = use { input -&gt;
          File(file).outputStream().use { output -&gt;
              input.copyTo(output)
          }
      }
  
  </code></pre>
  <p>if i using this fun i have exeption</p>
  <pre><code>E/AndroidRuntime: FATAL EXCEPTION: main
      Process: com.example.securityenginee, PID: 4154
      java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
          at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:549)
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)
       Caused by: java.lang.reflect.InvocationTargetException
          at java.lang.reflect.Method.invoke(Native Method)
          at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950) 
       Caused by: java.io.FileNotFoundException: 1606998235369.pdf: open failed: EROFS (Read-only file system)
          at libcore.io.IoBridge.open(IoBridge.java:496)
          at java.io.FileOutputStream.&lt;init&gt;(FileOutputStream.java:235)
          at java.io.FileOutputStream.&lt;init&gt;(FileOutputStream.java:186)
          at com.example.securityenginee.view.fragment.contragentAndAppInfo.ActsAndCountsFragment.saveToFile(ActsAndCountsFragment.kt:339)
  
  </code></pre>
  <p>my permissions</p>
  <pre><code>    &lt;uses-permission android:name=&quot;android.permission.WRITE_EXTERNAL_STORAGE&quot;
          tools:ignore=&quot;ScopedStorage&quot; /&gt;
      &lt;uses-permission android:name=&quot;android.permission.READ_EXTERNAL_STORAGE&quot; /&gt;
  </code></pre>
  <p>this i check permission</p>
  <pre><code>        val permissionStatus1 =
              ContextCompat.checkSelfPermission(requireContext(), Manifest.permission.WRITE_EXTERNAL_STORAGE)
          if (permissionStatus1 == PackageManager.PERMISSION_GRANTED) {
              Toast.makeText(requireContext(), &quot;PERMISSION_GRANTED&quot;, Toast.LENGTH_SHORT).show()
          }else if (permissionStatus1 == PackageManager.PERMISSION_DENIED){
              Toast.makeText(requireContext(), &quot;PERMISSION_DENIED&quot;, Toast.LENGTH_SHORT).show()
          }
  
  </code></pre>
  <p>all permission WRITE_EXTERNAL_STORAGE and READ_EXTERNAL_STORAGE send PERMISSION_GRANTED.</p>
  <p>now i change function save file and his doesnt work too</p>
  <pre><code>    fun writeBytesAsPdf(bytes: ByteArray) {
          val path = requireContext().getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS)
          var file = File.createTempFile(&quot;my_file&quot;, &quot;.pdf&quot;, path)
          val fos = FileOutputStream(file)
          fos.write(bytes)
          fos.flush()
          fos.close()
          Toast.makeText(requireContext(), &quot;test&quot;, Toast.LENGTH_SHORT).show()
      }
  </code></pre>