I am getting a FileNotFoundException but the file is there
<p>When I try to open a file that I selected via an Intent I get this error:</p>

<blockquote>
  <p>java.io.FileNotFoundException:
  /document/primary:Android/data/com.oli.myapp/Files/test.xml: open
  failed: ENOENT (No such file or directory)</p>
</blockquote>

<p>I don't know why this happens. The file exists because I selected it. Here is my Code:</p>

<p><strong>File selection:</strong></p>

<pre><code>Intent chooseFileXML = new Intent(Intent.ACTION_GET_CONTENT);
Uri uri = Uri.parse(new Helper(FunctionsActivity.this).getPathToAppFolder());                
chooseFileXML.setDataAndType(uri, "text/xml");
Intent intentXML = Intent.createChooser(chooseFileXML, getString(R.string.importXMLDatei));
startActivityForResult(intentXML, REQUEST_CODE_IMPORT_XML_FILE);
</code></pre>

<p><strong>Code to get it:</strong></p>

<pre><code>@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data){
    switch (requestCode){
        case REQUEST_CODE_IMPORT_XML_FILE:
            if(resultCode == RESULT_OK){

                String Fpath = data.getDataString();
                File file = new File(Fpath);
                Intent intent = new Intent(FunctionsActivity.this, CreateActivity.class);
                intent.setAction(Intent.ACTION_DEFAULT);
                intent.setData(Uri.parse(file.toURI().toString()));
                startActivity(intent);


            }
            break;
    }
}
</code></pre>

<p><strong>EDIT:</strong></p>

<pre><code>Uri uri = data.getData();
DocumentFile documentFile = DocumentFile.fromSingleUri(this, uri);
String type = documentFile.getType();
if(type.equals("text/xml")){
    try {
        InputStream inputStream = getContentResolver().openInputStream(uri);
        if(inputStream == null){
            throw new Exception();
        }
        BufferedReader r = new BufferedReader(new InputStreamReader(inputStream));
        StringBuilder total = new StringBuilder();
        String line;
        while ((line = r.readLine()) != null) {
            total.append(line).append('\n');
        }

        //Could read the file with no problems
        createWithXMLCode(total.toString());

    }catch (Exception e){
        e.printStackTrace();
        //TODO

    }
}else{
    //TODO
}
</code></pre>