title: Android - Get real path of a .txt file selected from the file explorer
body: <p>I am working on an app where I want to be able to export and import some data from the app, on a .txt file.
  The minimum API of the app is 21.</p>
  
  <p>The export part works well, but I am having trouble with the import part.</p>
  
  <p>I open the file explorer :</p>
  
  <pre><code>butImportPatient.setOnClickListener(new View.OnClickListener() {
  
      @Override
      public void onClick(View view) {
           Intent intent = new Intent();
           intent.setAction(Intent.ACTION_OPEN_DOCUMENT);
           intent.setType("*/*");
           startActivityForResult(intent, IMPORTPATIENT_ACTIVITY_REQUEST_CODE);
      }
  });
  </code></pre>
  
  <p>This looks like it is working.</p>
  
  <p>But my onActivityResult doesn't work, I didn't find how I can get the file from the Uri.</p>
  
  <p>For now, here is my code :</p>
  
  <pre><code>@Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
  
        if (requestCode == IMPORTPATIENT_ACTIVITY_REQUEST_CODE &amp;&amp; resultCode == RESULT_OK) {
              File file = new File(data.getData().getPath()) ;
              String path = file.getAbsolutePath() ;
              StringBuilder text = new StringBuilder();
  
              try {
                  BufferedReader br = new BufferedReader(new FileReader(path));
                  String line;
  
                  while ((line = br.readLine()) != null) {
                      text.append(line);
                      text.append("\n");
  
                  }
                  br.close();
              } catch (IOException e) {
                  e.printStackTrace();
              }
  
              AlertDialog.Builder builder = new AlertDialog.Builder(this) ;
              builder.setMessage(path)
                      .show() ;
  
          }
   }
  </code></pre>
  
  <p>It is a mix of multiple posts I saw here, but none seems to work.</p>
  
  <p>I get this path :</p>
  
  <pre><code>/document/home:List.txt
  </code></pre>
  
  <p>It creates FileNotFoundException. How can I get the real path of the file ?</p>