IOException
JavaERRORCommonI/O

I/O operation failed

Quick Answer

Use try-with-resources and catch specific subclasses before the generic IOException.

What this means

Base class for I/O failures — disk errors, network drops, broken pipes. Always use try-with-resources to guarantee stream closure.

Why it happens
  1. 1Disk full or hardware error during write
  2. 2Network connection dropped during stream read

Fix

Try-with-resources and specific catches

Try-with-resources and specific catches
try (var out = Files.newOutputStream(path)) {
    out.write(data);
} catch (FileNotFoundException e) {
    log.error("Path missing: {}", path);
} catch (IOException e) {
    log.error("IO failure: {}", e.getMessage());
}

Why this works

try-with-resources closes the stream even when an exception is thrown.

Code examples
Try-with-resourcesjava
try (BufferedReader r = Files.newBufferedReader(path)) {
    String line;
    while ((line = r.readLine()) != null) process(line);
}
Retry on transient IOjava
for (int i = 0; i < 3; i++) {
    try { return fetch(url); }
    catch (IOException e) { if (i == 2) throw e; }
}
Read all bytesjava
byte[] bytes = Files.readAllBytes(path);
Same error in other languages
Sources
Official documentation ↗

Java SE Documentation

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All Java errors