stanfordnlp/CoreNLP · error · RuntimeIOException
Exception in printToFile " + file.getAbsolutePath()
Error message
Exception in printToFile " + file.getAbsolutePath()
What it means
StringUtils.printToFile(File, String, boolean append) writes a message to a file via FileWriter/PrintWriter. Any exception during opening or writing is rethrown as RuntimeIOException('Exception in printToFile <file.getAbsolutePath()>'), so callers get a uniform runtime exception when the write fails.
Solutions
- Ensure the parent directory exists (file.getParentFile().mkdirs()) before calling printToFile
- Verify write permission on the target directory and that the path is not a directory itself
- Check available disk space/quota; inspect the cause of the RuntimeIOException for the exact IOException
Example fix
// before
StringUtils.printToFile(new File("out/result.txt"), text, false); // out/ missing
// after
File f = new File("out/result.txt");
f.getParentFile().mkdirs();
StringUtils.printToFile(f, text, false); Defensive patterns
Strategy: try-catch
Validate before calling
File f = new File(path);
if (f.isDirectory()) throw new IllegalStateException("Output path is a directory: " + f);
File parent = f.getParentFile();
if (parent != null && !parent.isDirectory()) parent.mkdirs(); Try / catch
try {
StringUtils.printToFile(file, message, append);
} catch (RuntimeIOException e) {
log.error("Failed writing " + file + ": " + e.getCause());
} Prevention
- Create parent directories before writing output files
- Check disk space and write permissions on output volumes, especially in containers
- Log to a writable temp path with a fallback if the primary output path fails
When it happens
Trigger: Calling printToFile when the target file cannot be created or written: nonexistent parent directory, no write permission, the path is a directory, or disk is full.
Common situations: Logging output to a directory that was never created; writing to read-only volumes in containers; output path pointing at an existing directory; exceeding disk quota on shared clusters.
Understand the failure class
Background: "failed to write file", "Could not save figure", "Error saving remote file" — file write failed: causes and fixes across languages and libraries — this error's family across 38 libraries.
Related errors
- Error creating data exporter
- Serializing classifier to
- Error opening output file
- RuntimeIOException wrapping IOException from write
- Exception: in printToFile
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/6dad99b687a07383.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/util/StringUtils.java:1248
if (pw != null) {
pw.flush();
pw.close();
}
}
}
/**
* Prints to a file. If the file already exists, appends if
* {@code append=true}, and overwrites if {@code append=false}.
*/
public static void printToFile(File file, String message, boolean append) {
PrintWriter pw = null;
try {
Writer fw = new FileWriter(file, append);
pw = new PrintWriter(fw);
pw.print(message);
} catch (Exception e) {
throw new RuntimeIOException("Exception in printToFile " + file.getAbsolutePath(), e);
} finally {
IOUtils.closeIgnoringExceptions(pw);
}
}
/**
* Prints to a file. If the file does not exist, rewrites the file;
* does not append.
*/
public static void printToFile(File file, String message) {
printToFile(file, message, false);
}
/**
* Prints to a file. If the file already exists, appends if
* {@code append=true}, and overwrites if {@code append=false}.
*/View on GitHub (pinned to 1b7edd19c4)