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ế.

7 bài · ~111 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.

    ~14 phút
  2. 02

    Path và Files — NIO.2 thay java.io.File

    Path immutable thay File, Files utility đồng nhất: readString, write, copy, move, delete với exception cụ thể. Vì sao API 1996 phải thay, và 90% task file I/O hằng ngày gói trong vài dòng.

    ~13 phút
  3. 03

    Duyệt thư mục và theo dõi file — walk, atomic swap, WatchService

    Files.walk/find/list duyệt cây thư mục, walkFileTree visitor pattern, file attribute theo OS. Pattern atomic swap cho ghi file an toàn và WatchService theo dõi thay đổi realtime.

    ~13 phút
  4. 04

    Serialization — cơ chế, serialVersionUID và transient

    Java native serialization hoạt động thế nào: marker interface + reflection, serialVersionUID làm version check, transient cho secret/resource, custom writeObject/readObject để encrypt và validate.

    ~14 phút
  5. 05

    Deserialization — lỗ hổng RCE và alternatives JSON/Protobuf

    Gadget chain biến ObjectInputStream.readObject thành remote code execution — câu chuyện 'Java deserialization apocalypse' 2015. Phòng chống với ObjectInputFilter (JEP 290) và alternatives: JSON, Protobuf, Avro.

    ~13 phút
  6. 06

    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.

    ~14 phút
  7. 07

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

    Bài thực hành khép lại module I/O & NIO — 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