iBotPeaches/Apktool · error · DirectoryException
Error copying file:
Error message
Error copying file:
What it means
Directory.copyToDir(inFileName, out, outFileName) copies one entry between Directory implementations (e.g. ZIP to filesystem) via streams; an IOException during the stream copy is wrapped in this DirectoryException naming the entry. It fires when the copy itself fails, not when the source is missing (missing sources take the containsDir/getFileInput paths).
Source
Thrown at brut.j.dir/src/main/java/brut/directory/Directory.java:254
public void copyToDir(Directory out, String fileName) throws DirectoryException {
copyToDir(fileName, out, fileName);
}
public void copyToDir(Directory out, String... fileNames) throws DirectoryException {
for (String fileName : fileNames) {
copyToDir(out, fileName);
}
}
public void copyToDir(String inFileName, Directory out, String outFileName) throws DirectoryException {
try {
if (containsDir(inFileName)) {
getDir(inFileName).copyToDir(out.createDir(outFileName));
} else {
BrutIO.copyAndClose(getFileInput(inFileName), out.getFileOutput(outFileName));
}
} catch (IOException ex) {
throw new DirectoryException("Error copying file: " + inFileName, ex);
}
}
public void copyToDir(File out) throws DirectoryException {
for (String fileName : getFiles(true)) {
copyToDir(out, fileName);
}
}
public void copyToDir(File out, String fileName) throws DirectoryException {
copyToDir(fileName, out, fileName);
}
public void copyToDir(File out, String... fileNames) throws DirectoryException {
for (String fileName : fileNames) {
copyToDir(out, fileName);
}
}View on GitHub (pinned to 79b63384d7)
Solutions
- Check the named entry's target path: parent directory exists, writable, enough free space
- Verify the source archive is intact (`unzip -t`) so its stream does not break mid-read
- Do not close or reuse the output Directory/stream while a bulk copyToDir loop is running
- Retry after fixing the environment; a persistent failure on one entry usually means a corrupt source entry
Example fix
// before
zipDir.copyToDir(inName, outDir, outName); // outDir parent missing -> Error copying file
// after
File parent = outDir.getDir().toFile();
if (!parent.exists() && !parent.mkdirs()) {
throw new IOException("Cannot create output dir: " + parent);
}
zipDir.copyToDir(inName, outDir, outName); Defensive patterns
Strategy: try-catch
Validate before calling
// Ensure target side is writable and source entry exists before copying
if (!out.containsDir(parentOf(outFileName)) && !canCreate) { /* pre-create */ }
// simplest: verify output Directory is open and its backing location writable
if (!new java.io.File(outLocation).canWrite()) throw new IOException("Output not writable"); Try / catch
try {
dir.copyToDir(inName, outDir, outName);
} catch (DirectoryException e) {
if (e.getMessage() != null && e.getMessage().startsWith("Error copying file")) {
// e.getMessage() names the entry; log it and continue with remaining entries or abort transactionally
} else { throw e; }
} Prevention
- Keep output directories opened and writable for the whole copy loop
- Never close the destination stream/zip mid-copyToDir
- Check disk space before bulk extraction
When it happens
Trigger: Copying a decoded resource/file entry into an output Directory whose target cannot be written (unwritable path, closed ZIP being written incorrectly, disk full) or whose source stream breaks mid-copy.
Common situations: Repackaging APKs in pipelines where the output zip stream was closed early, target dirs deleted mid-run, or filesystem quota exceeded during apktool b.
Related errors
- Could not generate:
- Could not decode arsc file.
- Error while reading chunk header.
- Error while skipping chunk.
- Error while skipping chunk header.
AI-assisted analysis of iBotPeaches/Apktool@79b63384d7 (2026-08-14).
Data as JSON: /api/errors/c9ff28e342103fec.
Report an issue: GitHub.