Section 09 · Stage 3: Master Java
Files, I/O & Robust Error Handling
Read and write files with java.nio, handle resources safely and design error handling that real applications can rely on.
What you will be able to do
- Create, read, copy, move and delete files and folders with java.nio.file
- Read and write text and binary data with the right reader, writer or stream
- Close every resource safely with try-with-resources, including your own classes
- Process CSV and other text formats and handle bad lines without crashing
- Design exceptions and error messages that a real application can rely on
What you will learn
9.1Exceptions in Depth9 lessons
Go past try and catch: the full exception hierarchy, checked versus unchecked, finally, chaining causes and reading complex stack traces.
- The exception family tree30 min
- Checked and unchecked exceptions35 min
- What to catch and what to leave alone35 min
- The finally block and its traps40 min
- Chain exceptions with a cause35 min
- Read a stack trace with Caused by35 min
- Rethrow and wrap checked exceptions40 min
- Why exceptions are not for normal flow40 min
- Exceptions in depth: common mistakes and practice45 min
9.2try-with-resources in Depth8 lessons
Close files and other resources correctly every time, even when things fail.
- Resources and why they must be closed30 min
- Closing resources the old way30 min
- try-with-resources step by step35 min
- Several resources and their close order35 min
- Suppressed exceptions35 min
- Write your own AutoCloseable class40 min
- Replace finally-close code with try-with-resources40 min
- try-with-resources: common mistakes and practice45 min
9.3Paths & Files9 lessons
Work with file paths and folders using Path and the Files class, in a way that works on every operating system.
- Path: naming a file in Java30 min
- Relative and absolute paths35 min
- Paths that work on Windows, macOS and Linux40 min
- Check, create and delete files and folders35 min
- Copy and move files with options35 min
- File size, dates and temporary files35 min
- List and walk folders40 min
- Copy or delete a whole folder tree safely45 min
- Paths and files: common mistakes and practice45 min
9.4Reading & Writing Text Files9 lessons
Read and write text files, small and large, with the right method, encoding and line endings for each job.
9.5Byte & Character Streams9 lessons
The classic java.io stream classes, how bytes and characters differ and how to wrap one stream in another.
- Bytes and characters30 min
- InputStream and OutputStream35 min
- Copy binary files such as images35 min
- Buffering and why it matters35 min
- Reader and Writer for characters35 min
- Bridge bytes to characters35 min
- PrintWriter for formatted output35 min
- Simple binary formats with data streams40 min
- Byte and character streams: common mistakes and practice45 min
9.6CSV & Structured Text8 lessons
Turn text files into objects and back, and deal with messy real data without crashing.
- Turn a CSV line into a record35 min
- Read a whole CSV file into objects35 min
- Quoted fields and commas inside values40 min
- Skip and report bad rows40 min
- Write CSV output and text reports40 min
- Properties files for settings40 min
- Write simple JSON text by hand40 min
- CSV and structured text: common mistakes and practice50 min
9.7Serialization Basics8 lessons
Save objects as bytes with Java serialization, learn its security risks and why text formats are usually chosen today.
- What serialization means35 min
- Object graphs and NotSerializableException40 min
- transient fields40 min
- serialVersionUID and class changes40 min
- Records and validation while reading45 min
- Why reading untrusted data is dangerous40 min
- Text formats as the usual choice35 min
- Serialization: common mistakes and practice50 min
9.8Designing Error Handling10 lessons
Decide what to throw, where to catch, what to log and what to tell the user, so errors are clear and nothing is silently lost.
- Checked or unchecked for your own exceptions35 min
- Design a good exception class35 min
- Validate early and fail fast35 min
- Translate exceptions at layer boundaries35 min
- Messages for users versus developers35 min
- Log errors with java.util.logging40 min
- Where to catch: anti-patterns40 min
- Retry and recover from file errors40 min
- Error handling interview review40 min
- Designing error handling: practice45 min
9.9Files & I/O Mini Projects5 lessons
Small, realistic programs that read, process and write real files with careful error handling.
