deeplearning4j/deeplearning4j · error · java.lang.RuntimeException
Error reading from stream for URI: + next
Error message
Error reading from stream for URI: + next
What it means
FileRecordReader.nextRecord() wraps any IOException thrown while opening or reading the stream for the current URI into an unchecked RuntimeException. This means the underlying file could not be read (missing, unreadable, deleted mid-iteration, or a failing stream creator function). The original IOException cause is discarded, so the message only tells you which URI failed.
Solutions
- Verify the URI exists and is readable before initializing the reader (Files.exists / Files.isReadable) and re-initialize with valid locations.
- Check filesystem/network availability for the URI; fix permissions or restore the file.
- Ensure the streamCreatorFn is configured to handle the URI scheme in use (file, hdfs, archive, etc.).
- Set a valid charset (default should be UTF-8) so Charset.forName inside the try block does not contribute failures.
Example fix
// before
RecordReader reader = new FileRecordReader();
reader.initialize(split); // split points at a file deleted afterwards
Record rec = reader.nextRecord();
// after
File f = new File(split.locations()[0]);
if (!f.exists() || !f.canRead()) {
throw new IllegalStateException("Input file missing/unreadable: " + f);
}
RecordReader reader = new FileRecordReader();
reader.initialize(split); Defensive patterns
Strategy: try-catch
Validate before calling
for (URI u : split.locations()) {
if (!Files.isReadable(Paths.get(u)))
throw new IllegalStateException("Unreadable input: " + u);
} Try / catch
try {
Record rec = reader.nextRecord();
} catch (RuntimeException e) {
if (e.getMessage().startsWith("Error reading from stream for URI")) {
log.error("Skipping unreadable URI", e);
// skip / fail over to backup location
} else throw e;
} Prevention
- Validate all split locations exist and are readable before initialize().
- Configure streamCreatorFn for every URI scheme you use.
- Avoid deleting/moving input files while a reader is active.
- Wrap long-running reads with retry on transient network filesystems.
When it happens
Trigger: Calling nextRecord() (directly or via next()/r) when streamCreatorFn.apply(next) returns a stream for a URI that cannot be opened, or loadFromStream throws IOException while parsing bytes for that URI.
Common situations: Input split locations point to files deleted or renamed after initialization; a network/remote URI became unreachable; file permissions changed; a listener (invokeListeners) or charset produced an IO error during loadFromStream; using archives/compressed files whose streams fail mid-read.
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
- Error during LineRecordReader reset
- Error reading from stream for URI: + uri
- Error reading URI file
- null
- Error loading checkpoint data from file
AI-assisted analysis of deeplearning4j/deeplearning4j@4c22ac5fe4 (2026-09-07).
Data as JSON: /api/errors/6e113aa6f081604c.
Report an issue: GitHub.
Appendix: source
Thrown at datavec/datavec-api/src/main/java/org/datavec/api/records/reader/impl/FileRecordReader.java:211
BufferedReader br = new BufferedReader(new InputStreamReader(dataInputStream));
StringBuilder sb = new StringBuilder();
String line;
while ((line = br.readLine()) != null) {
sb.append(line).append("\n");
}
return Collections.singletonList((Writable) new Text(sb.toString()));
}
@Override
public Record nextRecord() {
URI next = locationsIterator.next();
invokeListeners(next);
List<Writable> ret;
try(InputStream s = streamCreatorFn.apply(next)) {
ret = loadFromStream(next, s, Charset.forName(charset));
} catch (IOException e){
throw new RuntimeException("Error reading from stream for URI: " + next);
}
return new org.datavec.api.records.impl.Record(ret,new RecordMetaDataURI(next, FileRecordReader.class));
}
@Override
public Record loadFromMetaData(RecordMetaData recordMetaData) throws IOException {
return loadFromMetaData(Collections.singletonList(recordMetaData)).get(0);
}
@Override
public List<Record> loadFromMetaData(List<RecordMetaData> recordMetaDatas) throws IOException {
List<Record> out = new ArrayList<>();
for (RecordMetaData meta : recordMetaDatas) {
URI uri = meta.getURI();
List<Writable> list;View on GitHub (pinned to 4c22ac5fe4)