{"record":{"id":"7ec28ec3f2512514","repo":"lingochamp/FileDownloader","slug":"create-parent-directory-failed-please-make-sure-y","errorCode":null,"errorMessage":"Create parent directory failed, please make sure you have permission to create file or directory on the path: %s","messagePattern":"Create parent directory failed, please make sure you have permission to create file or directory on the path: (.+?)","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"library/src/main/java/com/liulishuo/filedownloader/DownloadTaskHunter.java","lineNumber":552,"sourceCode":"            }\n        }\n\n        final File dir;\n        if (origin.isPathAsDirectory()) {\n            dir = new File(origin.getPath());\n        } else {\n            final String dirString = FileDownloadUtils.getParent(origin.getPath());\n            if (dirString == null) {\n                throw new InvalidParameterException(\n                        FileDownloadUtils.formatString(\"the provided mPath[%s] is invalid,\"\n                                + \" can't find its directory\", origin.getPath()));\n            }\n            dir = new File(dirString);\n        }\n\n        if (!dir.exists()) {\n            if (!dir.mkdirs() && !dir.exists()) {\n                throw new IOException(FileDownloadUtils.\n                        formatString(\"Create parent directory failed, please make sure \"\n                                        + \"you have permission to create file or directory \"\n                                        + \"on the path: %s\",\n                                dir.getAbsolutePath()));\n            }\n        }\n    }\n\n    private int getId() {\n        return mTask.getRunningTask().getOrigin().getId();\n    }\n\n    @SuppressWarnings(\"checkstyle:emptyblock\")\n    @Override\n    public void start() {\n        if (mStatus != FileDownloadStatus.toLaunchPool) {\n            FileDownloadLog.w(this, \"High concurrent cause, this task %d will not start,\"\n                            + \" because the of status isn't toLaunchPool: %d\",","sourceCodeStart":534,"sourceCodeEnd":570,"githubUrl":"https://github.com/lingochamp/FileDownloader/blob/6237a8cac174bcc916e4342b14ab1ab72a5768d4/library/src/main/java/com/liulishuo/filedownloader/DownloadTaskHunter.java#L534-L570","documentation":"DownloadTaskHunter.prepare() throws IOException when the parent directory of the target path does not exist and mkdirs() fails to create it. This is a filesystem/permission problem on the device (e.g. unmounted external storage or missing WRITE_EXTERNAL_STORAGE).","triggerScenarios":"Target path under a directory that cannot be created: external storage unmounted, no storage permission, or path on read-only volume.","commonSituations":"Android 6.0+ without runtime WRITE_EXTERNAL_STORAGE permission; saving to /sdcard/... on scoped-storage Android 10+; storage removed mid-session.","solutions":["Request WRITE_EXTERNAL_STORAGE (or use app-scoped storage like context.getExternalFilesDir(null)) at runtime.","Check File.canWrite() / Environment.getExternalStorageState() before creating the task.","Download to a directory that already exists or your app's private directory.","Catch IOException around start/queue set usage and surface a user-facing message."],"exampleFix":"// before\nFileDownloader.getImpl().create(url, \"/sdcard/mydir/file.zip\");\n\n// after\nFile dir = new File(context.getExternalFilesDir(null), \"mydir\");\nif (!dir.exists()) dir.mkdirs();\nif (!dir.canWrite()) throw new IOException(\"dir not writable\");\nFileDownloader.getImpl().create(url, new File(dir, \"file.zip\").getAbsolutePath());","handlingStrategy":"try-catch","validationCode":"File dir = new File(FileDownloadUtils.getParent(path));\nif (!dir.exists() && !dir.mkdirs()) throw new IOException(\"cannot create \" + dir);\nif (!dir.canWrite()) throw new IOException(\"not writable: \" + dir);","typeGuard":null,"tryCatchPattern":"try { task.start(); } catch (IOException e) { requestStoragePermissionOrFallbackDir(); }","preventionTips":["Request storage permissions at runtime before starting downloads.","Prefer app-scoped storage (getExternalFilesDir) on Android 10+.","Check Environment.getExternalStorageState() equals MEDIA_MOUNTED.","Pre-create directories during app setup."],"tags":["android","filesystem","permissions","mkdir"],"backgroundTag":"mkdir-permission-denied","analyzedSha":"6237a8cac174bcc916e4342b14ab1ab72a5768d4","analyzedAt":"2026-09-08T23:50:48.168Z","contentChangedAt":"2026-09-08T23:50:48.168Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}