title: Save Java.io.File to Android FileSystem on KitKat and above
body: <p>I'm working on an app that saves thermal images from a FLIR camera to the SD Card on the phone. 
  I'm using Android Marshmallow and I have to use the FLIR SDK.</p>
  
  <p>In the FLIR SDK is a class "Frame". The class has a method "Frame.save", that needs a Java.io.File to save a thermal image: This is from the documentation:</p>
  
  <pre><code>public void save(java.io.File file,
               RenderedImage.Palette previewPalette,
               RenderedImage.ImageType previewImageType)
        throws java.io.IOException,
               java.lang.IllegalArgumentException
  </code></pre>
  
  <p><i>Saves a thermal JPEG file, which has a rendered visual preview and embedded thermal data</i></p>
  
  <p>When I understand it right, on KitKat or higher I have to use the Storage Accsess Framework. So I used it. Send a Intent and get back a Uri to a picked folder on the SD Card. Now to the tricky part. This funktion should create a File and return a Java.io.File that ready for the "Frame.save" method.</p>
  
  <pre><code>public File getJavaFile (String Name, Uri myUri) {
  
  
        DocumentFile pickedDir = DocumentFile.fromTreeUri(context, myUri);                      // Document file aus URI
        DocumentFile DocumentFile = pickedDir.createFile("image/plain", Name + ".jpg" );
  
        File file = new File(DocumentFile.getUri().getPath());
        if(file.canWrite()){
            Log.d(TAG + "/getJavaFile", "File can write");
        }else {
            Log.e(TAG + "/getJavaFile", "File cannot write");
          }
  
        Log.d(TAG + "/getJavaFile:", "File Created:" + file.getPath());
  
  
      return file;
  }
  </code></pre>
  
  <p>The file that the function return is not readable or writeable...
  Otherwise, when I try to create a File directly, like so:</p>
  
  <pre><code>String root = Environment.getExternalStorageDirectory().toString();
  File file = new File(root + "/saved_images");
  Log.d(TAG, file.getPath());
  </code></pre>
  
  <p>Then the the system always gives me this emulated folder:</p>
  
  <pre><code>E/MainActivity: /storage/emulated/0/saved_images
  </code></pre>
  
  <p>So the question is: How to get a useable Java File, thats stored on the public storage space... Thank you for your time!</p>