OLHub

I/O & NIO

File I/O cổ điển (InputStream/Reader), NIO.2 (Path/Files), byte vs char stream, buffered I/O, serialization (Serializable caveats), đọc file với Stream API. Khi nào dùng API nào cho workload thực tế.

5 bài · ~118 phútMiễn phí

Nội dung

Danh sách bài học

  1. 01

    I/O cổ điển — InputStream, Reader, buffered wrapper

    Byte stream vs char stream, decorator pattern của java.io, vì sao BufferedReader nhanh hơn FileReader hàng trăm lần. Charset và bug latent khi không specify encoding.

    ~22 phút
  2. 02

    NIO.2 — Path và Files, API hiện đại

    Path thay File, Files utility với 60+ method đồng nhất (readString, write, copy, walk, lines). Watch service theo dõi file realtime. Atomic swap pattern cho ghi file an toàn.

    ~22 phút
  3. 03

    Serialization — Serializable và những cạm bẫy

    Java native serialization, serialVersionUID, transient, custom writeObject/readObject. Câu chuyện CVE deserialization — lỗ hổng số 1 Java 2015. Vì sao team hiện đại chuyển sang JSON/Protobuf.

    ~22 phút
  4. 04

    Stream file — Files.lines, memory-mapped, channel

    Xử lý file lớn stream-based với Files.lines, try-with-resources. Memory-mapped file (MappedByteBuffer) cho random access, FileChannel + Buffer cho control chi tiết. Pattern xử lý file 10GB không OOM.

    ~22 phút
  5. 05

    Mini-challenge: Log aggregator với NIO.2 và Stream

    Bài thực hành khép lại Module 11 — walk thư mục log, stream từng file, parse line, aggregate thống kê, output report CSV. Pattern production thực tế.

    ~30 phút