✅ 1. java.io
— Traditional I/O (Streams API)
This is the main package that contains most of the classic input/output stream classes.
🔹 Byte Streams
Type | Class Names |
---|
Input | InputStream , FileInputStream , BufferedInputStream , DataInputStream , ByteArrayInputStream , ObjectInputStream , PipedInputStream |
Output | OutputStream , FileOutputStream , BufferedOutputStream , DataOutputStream , ByteArrayOutputStream , ObjectOutputStream , PipedOutputStream |
🔹 Character Streams
Type | Class Names |
---|
Reader | Reader , FileReader , BufferedReader , CharArrayReader , StringReader , InputStreamReader |
Writer | Writer , FileWriter , BufferedWriter , CharArrayWriter , StringWriter , OutputStreamWriter |
✅ 2. java.nio
and java.nio.file
— New I/O (NIO & NIO.2)
Introduced in Java 1.4 and extended in Java 7 (NIO.2), these packages contain:
Channel
classes (e.g., FileChannel
, SocketChannel
)Buffer
classes (e.g., ByteBuffer
, CharBuffer
)Path
, Files
, FileSystems
(modern file operations)WatchService
(directory monitoring)Asynchronous*
classes for non-blocking I/O
🧠 Summary Table
Package | Purpose |
---|
java.io | Classic I/O streams (blocking) |
java.nio | Buffers, channels, selectors |
java.nio.file | Modern file system API (Path, Files, etc.) |
java.nio.channels | Channels like FileChannel , SocketChannel |