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 work

View on GitHub (pinned to e5d74d3aa9)

Solutions

  1. Use app-scoped cache dirs (getCacheDir/getExternalCacheDir)
  2. Add android:requestLegacyExternalStorage="true" in the manifest for Android 10 targets still using shared paths
  3. Verify storage mount state and permissions before constructing the proxy
  4. 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

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


AI-assisted analysis of CarGuo/GSYVideoPlayer@e5d74d3aa9 (2026-08-14). Data as JSON: /api/errors/3e16a9fca611a357. Report an issue: GitHub.