stanfordnlp/CoreNLP · error · RuntimeIOException
slurpFile IO problem
Error message
slurpFile IO problem
What it means
slurpFileNoExceptions() wraps failures of slurpFile(filename, encoding) in a RuntimeIOException with message "slurpFile IO problem". It is thrown when reading the entire text of a file fails with an IOException (missing file, unreadable file, wrong encoding, etc.). The original IOException is chained as the cause, so check getCause() for the real reason.
Solutions
- Verify the file path exists and is readable: new File(path).canRead() before calling, or print new File(path).getAbsolutePath() to check path resolution.
- Inspect e.getCause() (the chained IOException) to see the underlying reason (FileNotFoundException vs UnsupportedEncodingException).
- Check the encoding string is a valid Java charset name, or use the File overload without encoding (defaults to UTF-8 in recent versions).
- If you want the checked exception instead, call IOUtils.slurpFile(filename, encoding) directly and handle IOException.
Example fix
// before
String text = IOUtils.slurpFileNoExceptions(cfgPath, "UTF-8");
// after
File f = new File(cfgPath);
if (!f.isFile() || !f.canRead()) {
throw new IllegalArgumentException("Cannot read config: " + f.getAbsolutePath());
}
String text = IOUtils.slurpFileNoExceptions(f, StandardCharsets.UTF_8.name()); Defensive patterns
Strategy: try-catch
Validate before calling
File f = new File(path);
if (!f.isFile()) throw new IllegalStateException("Not a file: " + f.getAbsolutePath());
if (!f.canRead()) throw new IllegalStateException("Not readable: " + f.getAbsolutePath());
Charset.forName(encoding); // validate charset name Try / catch
try {
String text = IOUtils.slurpFileNoExceptions(f, encoding);
} catch (RuntimeIOException e) {
throw new IOException("Failed to slurp " + f.getAbsolutePath() + ": " + e.getCause(), e.getCause());
} Prevention
- Always print/log getAbsolutePath() when a read fails — relative paths resolve against the process CWD.
- Validate the encoding string with Charset.forName() at startup.
- Prefer the checked IOUtils.slurpFile if you need to handle missing files explicitly.
When it happens
Trigger: Calling IOUtils.slurpFileNoExceptions(filename, encoding) when slurpFile throws: the file does not exist, the path is a directory, the process lacks read permission, the stream cannot be opened, or the reader/decoder fails due to an invalid or unsupported encoding.
Common situations: Config files or corpus files specified with a wrong path or relative path resolved against an unexpected working directory; typo'd charset name (e.g. "utf8" typos are usually fine but "UTF_8" is not); files deleted or moved between existence-check and read; running as a user without read permission.
Understand the failure class
Background: "failed to read file", EACCES, ENOENT and "could not read <path>" errors: when a program can't read a file from disk — this error's family across 49 libraries.
Related errors
- edu.stanford.nlp.io.RuntimeIOException
- Error reading saved links
- error loading
- Could not read from float initial weight file
- Could not read from double initial weight file
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/df4a62bef7433847.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/io/IOUtils.java:1192
*/
public static String slurpFile(String filename, String encoding)
throws IOException {
Reader r = readerFromString(filename, encoding);
return IOUtils.slurpReader(r);
}
/**
* Returns all the text in the given file with the given
* encoding. If the file cannot be read (non-existent, etc.), then
* the method throws an unchecked RuntimeIOException. If the caller
* is willing to tolerate missing files, they should catch that
* exception.
*/
public static String slurpFileNoExceptions(String filename, String encoding) {
try {
return slurpFile(filename, encoding);
} catch (IOException e) {
throw new RuntimeIOException("slurpFile IO problem", e);
}
}
/**
* Returns all the text in the given file
*
* @return The text in the file.
*/
public static String slurpFile(String filename) throws IOException {
return slurpFile(filename, defaultEncoding);
}
/**
* Returns all the text at the given URL.
*/
public static String slurpURLNoExceptions(URL u, String encoding) {
try {
return IOUtils.slurpURL(u, encoding);View on GitHub (pinned to 1b7edd19c4)