MuntashirAkon/AppManager · error · IOException

Could not open file for reading:

Error message

Could not open file for reading: 

What it means

Thrown by PathImpl.openInputStream() when opening an InputStream on an ExtendedRawDocumentFile-backed file fails. The underlying FileInputStream could not be created (e.g. the file disappeared, is unreadable, or the raw file handle is stale). The original IOException is chained as the cause.

Source

Thrown at app/src/main/java/io/github/muntashirakon/io/PathImpl.java:1235

        String mode = "w" + (append ? "a" : "t");
        OutputStream os = context.getContentResolver().openOutputStream(documentFile.getUri(), mode);
        if (os == null) {
            throw new IOException("Could not resolve Uri: " + documentFile.getUri());
        }
        return os;
    }

    @NonNull
    public InputStream openInputStream() throws IOException {
        DocumentFile documentFile = resolveFileOrNull(this.documentFile);
        if (documentFile == null) {
            throw new IOException(this.documentFile.getUri() + " is a directory");
        }
        if (documentFile instanceof ExtendedRawDocumentFile) {
            try {
                return Objects.requireNonNull(getFile()).newInputStream();
            } catch (IOException e) {
                throw new IOException("Could not open file for reading: " + documentFile.getUri(), e);
            }
        } else if (documentFile instanceof VirtualDocumentFile) {
            return ((VirtualDocumentFile) documentFile).openInputStream();
        }
        try {
            InputStream is = context.getContentResolver().openInputStream(documentFile.getUri());
            if (is == null) {
                throw new IOException("Could not resolve Uri: " + documentFile.getUri());
            }
            return is;
        } catch (SecurityException e) {
            throw new IOException(e);
        }
    }

    public FileChannel openFileChannel(int mode) throws IOException {
        DocumentFile documentFile = resolveFileOrNull(this.documentFile);
        if (documentFile == null) {

View on GitHub (pinned to 0152f468fc)

Solutions

  1. Re-check path existence with Path.exists() and retry the open
  2. Verify the app/root has read permission on the underlying raw file
  3. Catch IOException around openInputStream and surface documentFile.getUri() for diagnosis
  4. Check that storage volume is still mounted before opening

Example fix

// before
InputStream is = path.openInputStream();
// after
InputStream is;
try {
    is = path.openInputStream();
} catch (IOException e) {
    if (!path.exists()) throw new FileNotFoundException(path.getUri().toString());
    throw e;
}
Defensive patterns

Strategy: try-catch

Validate before calling

if (!path.exists()) throw new FileNotFoundException(path.getUri().toString());

Type guard

boolean isOpenable(Path p) { return p.exists() && p.isFile(); }

Try / catch

try { InputStream is = path.openInputStream(); ... } catch (IOException e) { throw new IOException("Failed to open " + path.getUri(), e); }

Prevention

When it happens

Trigger: Calling Path.openInputStream() or Path.newInputStream() on a path whose resolved DocumentFile is an ExtendedRawDocumentFile, and File.newInputStream() throws IOException (file deleted between resolution and open, permission revoked, or corrupted raw file).

Common situations: Files deleted by another process between exists() check and open; storage unmounted; SELinux or root-fs restrictions blocking raw reads; reading files under /data via the extended raw layer without root privileges.

Understand the failure class

Background: "open() failed", "failed to open file", "cannot create file" — what a file open error means and how to fix it — this error's family across 42 libraries.

Related errors


AI-assisted analysis of MuntashirAkon/AppManager@0152f468fc (2026-09-12). Data as JSON: /api/errors/2e01652a9a956269. Report an issue: GitHub.