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
- Re-check path existence with Path.exists() and retry the open
- Verify the app/root has read permission on the underlying raw file
- Catch IOException around openInputStream and surface documentFile.getUri() for diagnosis
- 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
- Re-check exists() immediately before opening
- Do not cache Path objects across storage events (unmount, revoke)
- Chain the cause exception when rethrowing for diagnostics
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
- Could not backup data
- Unable to open output stream.
- Couldn't find any writable Obb dir
- Could not get backup files.
- Could not retrieve metadata from backup.
AI-assisted analysis of MuntashirAkon/AppManager@0152f468fc (2026-09-12).
Data as JSON: /api/errors/2e01652a9a956269.
Report an issue: GitHub.