Fundamentals · Easy · Free
How do stdin/stdout and file I/O work at a high level in any language?
FresherFundamentalsProgramming Fundamentals
stdin, stdout, and files
Programs communicate through streams: bytes flow from input sources (keyboard, file, socket) to your code and from your code to outputs (console, file, HTTP response). The OS buffers I/O and exposes a small API—read/write or higher-level scanners.
- stdin (standard input): Default input stream—keyboard in terminal apps.
- stdout / stderr: Normal output vs error channel (logs still visible when stdout is piped).
- File I/O: Open path → read/write bytes or lines → close (or use try-with-resources).
- Encoding: Text files are bytes + charset (UTF-8)—always specify encoding in production.
java
try (BufferedReader br = new BufferedReader(new FileReader("data.txt"))) {
String line;
while ((line = br.readLine()) != null) System.out.println(line);
}Say stream abstraction—same read loop works for file or network socket with different stream implementation.