title: creating file : No such file or directory android
body: <p>What I'm trying to do is pretty simple: Pick an image from my phone (anywhere) and convert it to a <code>File</code>. My final goal is to use this upload this file into my DB (a thing that I already succeed with a picture that I took from the camera).</p>
  
  <p>My situation is: when I'm trying to create my file from the path given by the Uri. It doesn't work. I have read from some topics on SO and some other websites that sometimes it's impossible to create a file from the Uri's path like on these websites : </p>
  
  <p><a href="https://freakycoder.com/android-notes-73-how-to-get-real-path-from-uri-2f78320987f5" rel="nofollow noreferrer">https://freakycoder.com/android-notes-73-how-to-get-real-path-from-uri-2f78320987f5</a></p>
  
  <p><a href="https://www.dev2qa.com/how-to-get-real-file-path-from-android-uri/" rel="nofollow noreferrer">https://www.dev2qa.com/how-to-get-real-file-path-from-android-uri/</a></p>
  
  <p>Also tried that way : <a href="https://stackoverflow.com/questions/21829816/android-get-file-with-path">Android - Get file with path</a></p>
  
  <p>but still doesn't work.</p>
  
  <p>My current code :
  How I'm picking up the picture :</p>
  
  <pre><code>public void exportPicture() {
  
          Intent intent = new Intent(Intent.ACTION_PICK,
                  android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
  
          startActivityForResult(intent, READ_REQUEST_CODE);
      }
  </code></pre>
  
  <p>how my Uri is filling :</p>
  
  <pre><code>@Override
  public void onActivityResult(int requestCode, int resultCode, Intent data) {
          super.onActivityResult(requestCode, resultCode, data);
          if (requestCode == READ_REQUEST_CODE &amp;&amp; resultCode == Activity.RESULT_OK) {
              if (data != null) {
                  photoURI = data.getData();
                  Log.d("URI", "Uri:" + photoURI.toString());
              }
          }
      }
  </code></pre>
  
  <p>how I'm trying to create the file :</p>
  
  <pre><code>if (photoURI != null) {
    File file = new File (photoURI.getPath());
  }
  </code></pre>
  
  <p>I got the following error : </p>
  
  <blockquote>
    <p>java.io.FileNotFoundException: /external/file/186142 (No such file or
    directory)</p>
  </blockquote>
  
  <p>I'm under Oreo.</p>
  
  <p>EDIT : Answer found here : <a href="https://stackoverflow.com/a/52095352">stackoverflow.com/a/52095352</a></p>