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
- Ensure the parent directory of 'temp' exists and is writable (call temp.getParentFile().mkdirs()) before constructing the writer.
- Verify write permission and available space on the target volume before starting the download.
- Use context.getCacheDir() or getExternalCacheDir() for temp files, which are always writable by the app.
- 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
- Use context.getCacheDir() for temp files — always writable by the app.
- Call mkdirs() on the temp file's parent directory before creating it.
- Check available disk space before starting a download that needs a temp buffer.
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
- Cannot create the file
- Failed to create the tree from Uri
- SAF not available
- Directory with the same name found but cannot delete
- Cache dir does not exist >
AI-assisted analysis of TeamNewPipe/NewPipe@9e8be09156 (2026-08-14).
Data as JSON: /api/errors/e835154ffff43d38.
Report an issue: GitHub.