TeamNewPipe/NewPipe · error · IOException

Cannot create a temporal file

Error message

Cannot create a temporal file

What it means

Thrown by CircularFileWriter's constructor when the auxiliary temp File does not exist and createNewFile() returns false. CircularFileWriter uses a secondary temp file as a circular buffer for download data; if it cannot create that temp file (path unwritable, parent missing, permission denied), the writer cannot operate and throws. Note: if the temp file already exists, this check is skipped.

Source

Thrown at app/src/main/java/us/shandian/giga/io/CircularFileWriter.java:35

    private static final int THRESHOLD_AUX_LENGTH = 15 * 1024 * 1024;// 15 MiB

    private final OffsetChecker callback;

    public ProgressReport onProgress;
    public WriteErrorHandle onWriteError;

    private long reportPosition;
    private long maxLengthKnown = -1;

    private BufferedFile out;
    private BufferedFile aux;

    public CircularFileWriter(SharpStream target, File temp, OffsetChecker checker) throws IOException {
        Objects.requireNonNull(checker);

        if (!temp.exists()) {
            if (!temp.createNewFile()) {
                throw new IOException("Cannot create a temporal file");
            }
        }

        aux = new BufferedFile(temp);
        out = new BufferedFile(target);

        callback = checker;

        reportPosition = NOTIFY_BYTES_INTERVAL;
    }

    private void flushAuxiliar(long amount) throws IOException {
        if (aux.length < 1) {
            return;
        }

        out.flush();
        aux.flush();

View on GitHub (pinned to 9e8be09156)

Solutions

  1. Ensure the parent directory of 'temp' exists and is writable (call temp.getParentFile().mkdirs()) before constructing the writer.
  2. Verify write permission and available space on the target volume before starting the download.
  3. Use context.getCacheDir() or getExternalCacheDir() for temp files, which are always writable by the app.
  4. Catch IOException and retry with a fallback temp location.

Example fix

// before
new CircularFileWriter(target, tempFile, checker);

// after — guarantee parent dir exists
File parent = tempFile.getParentFile();
if (parent != null && !parent.exists() && !parent.mkdirs()) {
    throw new IOException("Cannot create temp parent dir: " + parent);
}
new CircularFileWriter(target, tempFile, checker);
Defensive patterns

Strategy: validation

Validate before calling

// Ensure temp file parent exists before constructing the writer:
File parent = temp.getParentFile();
if (parent != null && !parent.exists() && !parent.mkdirs()) {
    throw new IOException("Cannot create temp parent dir: " + parent);
}

Try / catch

try {
    CircularFileWriter writer = new CircularFileWriter(target, temp, checker);
} catch (IOException e) {
    if ("Cannot create a temporal file".equals(e.getMessage())) {
        // retry with a cache-dir temp location
        temp = new File(context.getCacheDir(), temp.getName());
        writer = new CircularFileWriter(target, temp, checker);
    } else throw e;
}

Prevention

When it happens

Trigger: new CircularFileWriter(target, temp, checker) where !temp.exists() && !temp.createNewFile(). createNewFile returns false when the parent directory does not exist, is read-only, or the process lacks write permission at that path.

Common situations: Download temp directory was deleted or is on unmounted storage; app lost write permission to the chosen path; the temp path's parent was never created (mkdirs not called); disk full so createNewFile fails; path points to a file:// location on read-only external storage.

Related errors


AI-assisted analysis of TeamNewPipe/NewPipe@9e8be09156 (2026-08-14). Data as JSON: /api/errors/e835154ffff43d38. Report an issue: GitHub.