CarGuo/GSYVideoPlayer · error · IOException
Directory %s can't be created
Error message
Directory %s can't be created
What it means
Files.makeDir's second failure mode: when the directory does not exist and mkdirs() returns false (or a concurrent delete raced the check), it throws IOException('Directory <path> can't be created'). Called from FileCache's constructor, it surfaces as ProxyCacheException when the proxy cannot create the cache directory it was configured with.
Source
Thrown at gsyVideoPlayer-proxy_cache/src/main/java/com/danikula/videocache/file/Files.java:31
import java.util.List;
/**
* Utils for work with files.
*
* @author Alexey Danilov (danikula@gmail.com).
*/
class Files {
static void makeDir(File directory) throws IOException {
if (directory.exists()) {
if (!directory.isDirectory()) {
throw new IOException("File " + directory + " is not directory!");
}
} else {
boolean isCreated = directory.mkdirs();
if (!isCreated) {
throw new IOException(String.format("Directory %s can't be created", directory.getAbsolutePath()));
}
}
}
static List<File> getLruListFiles(File directory) {
List<File> result = new LinkedList<>();
File[] files = directory.listFiles();
if (files != null) {
result = Arrays.asList(files);
Collections.sort(result, new LastModifiedComparator());
}
return result;
}
static void setLastModifiedNow(File file) throws IOException {
if (file.exists()) {
long now = System.currentTimeMillis();
boolean modified = file.setLastModified(now); // on some devices (e.g. Nexus 5) doesn't workView on GitHub (pinned to e5d74d3aa9)
Solutions
- Use app-scoped cache dirs (getCacheDir/getExternalCacheDir)
- Add android:requestLegacyExternalStorage="true" in the manifest for Android 10 targets still using shared paths
- Verify storage mount state and permissions before constructing the proxy
- Fall back to internal cache dir when external is unavailable
Example fix
// before
File dir = new File("/sdcard/videocache");
// after
File dir = ctx.getExternalCacheDir() != null
? new File(ctx.getExternalCacheDir(), "videocache")
: new File(ctx.getCacheDir(), "videocache"); Defensive patterns
Strategy: validation
Validate before calling
File dir = new File(context.getCacheDir(), "proxy");
if (!dir.exists()) {
boolean ok = dir.mkdirs();
if (!ok && !dir.isDirectory()) {
dir = context.getCacheDir(); // guaranteed writable fallback
}
} Try / catch
catch (IOException e) {
if (String.valueOf(e.getMessage()).contains("can't be created")) {
// fall back to internal cache dir and retry construction
} else throw e;
} Prevention
- Default to internal cache dirs; treat external as optional
- Validate permissions and mount state before creating directories
- Keep one proxy instance and one cache dir per app
When it happens
Trigger: new FileCache(...) -> Files.makeDir(parent) where the cache directory is missing and mkdirs() fails: missing write permission on the parent (scoped storage, unmounted external volume), a parent path component existing as a file, or disk/filesystem errors.
Common situations: Scoped storage restrictions, missing legacy storage flag (requestLegacyExternalStorage) on Android 10, unmounted removable storage, read-only fs.
Related errors
- File %s is not directory!
- Error reading source ${errorsCount} times
- Error opening %s as disc cache
- Error using file ${file} as disc cache
- Error append cache: cache file %s is completed!
AI-assisted analysis of CarGuo/GSYVideoPlayer@e5d74d3aa9 (2026-08-14).
Data as JSON: /api/errors/3e16a9fca611a357.
Report an issue: GitHub.