title: Android: reading from text file - finished with exception open failed: ENOENT (No such file or directory)
body: <p>I am new in Android apps development (java) and I need help.
  I need read text file and store each line to List&lt;String&gt;.
  I have read many discusions here in stackoverflow. One of them inspired my code. But I can not solve my problem ...</p>
  <p>So I call file picker like bellow:</p>
  <pre><code>    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
  intent.setType(&quot;*/*&quot;);
  intent.addCategory(Intent.CATEGORY_OPENABLE);
  
  try {                                
      startActivityForResult(Intent.createChooser(intent, getString(R.string.vyber_soubor)), VYBER_SOUBORU_POZNAMKA);
  } catch (android.content.ActivityNotFoundException ex) {
      Toast.makeText(kontext, &quot;SeznamPoznamek::onCreate::tlPridej.setOnClickListener - Please install a File Manager.&quot;, Toast.LENGTH_LONG).show();
  }
  </code></pre>
  <p>and in function onActivityResult (bellow is shown only neccessary part, the rest of function is marked as dots) pick from intent uri of choosed file. With function getPath
  extract from uri file-path as a string. This file-path string I send to function &quot;importujTextovouPoznamku&quot; where I want to read lines from text file.
  But at line &quot;FileInputStream fis = new FileInputStream(mujExterniSoubor);&quot; is exception
  (&quot;java.io.FileNotFoundException: /document/primary:DCIM/veci_svor.txt: open failed: ENOENT (No such file or directory)&quot;) threw</p>
  <p>In manifest is:
  &lt;uses-permission android:name=&quot;android.permission.WRITE_EXTERNAL_STORAGE&quot; /&gt;</p>
  <p>and app has permition to write into storage.</p>
  <p>I am surprised that I have double dot in file path (you can see my file-path string in exception, there is also visible that my file is stored at DCIM folder)</p>
  <p>And second surprise for me is that at real phone Huawei honor  6A (android 6) this code works (but only at this phone), but no at other phone Motorola e5 plus (android 8) or virtual machines (android 6 or 8).</p>
  <p>Please could anybody help me or advice what I should try to continue in my code without exception
  Thanks fik236</p>
  <p>some part of code:</p>
  <pre><code>    private String getPath(Uri uri) {
          String path = null;
          String[] projection = { MediaStore.Files.FileColumns.DATA };
          Cursor cursor = getContentResolver().query(uri, projection, null, null, null);
  
          if(cursor == null){
              path = uri.getPath();
          }
          else{
              cursor.moveToFirst();
              int column_index = cursor.getColumnIndexOrThrow(projection[0]);
              path = cursor.getString(column_index);
              cursor.close();
          }
  
          return ((path == null || path.isEmpty()) ? (uri.getPath()) : path);
      }
  
  public void onActivityResult(int kodVolani, int vysledekVolani, Intent mujVraceciIntent) {
          super.onActivityResult(kodVolani, vysledekVolani, mujVraceciIntent);
      .
      .
      .
      } else if ( kodVolani== VYBER_SOUBORU_POZNAMKA) {
              Uri uri = mujVraceciIntent.getData();
              String src = getPath(uri);
              importujTextovouPoznamku(src);
      }
      .
      .
      .
  
  
  public void importujTextovouPoznamku (String jmenoSouboru) {
      List&lt;String&gt; precteneRadky = new ArrayList&lt;&gt;();
  
          File mujExterniSoubor = new File(jmenoSouboru);
          try {
              FileInputStream fis = new FileInputStream(mujExterniSoubor); //problem
              DataInputStream in = new DataInputStream(fis);
              BufferedReader br = new BufferedReader(new InputStreamReader(in));
  
              String radek;
              while ((radek = br.readLine()) != null) {
                  precteneRadky.add(radek);
              }
              br.close();
              in.close();
              fis.close();
          } catch (IOException e) {
              e.printStackTrace();
              Toast.makeText(getBaseContext(),&quot;SeznamPoznamek.java::prectiRadkyZeSouboru:&quot; + e.getMessage(), Toast.LENGTH_LONG).show();
          }
      .
      .
      .
  </code></pre>