java.io and java.nio

PrintStream

PrintStream is a subclass of FilterOutputStream that adds functionality for printing various data values in human-readable text format. It’s commonly used for printing output to the console, files, or any other output stream. Automatically converts primitives and objects to string representation. Methods like print(), println(), and printf() are provided. You can control whether to auto-flush …

PrintStream Read More »

PipedInputStream

PipedInputStream is used to read data written to a connected PipedOutputStream. It provides a communication pipe between two threads, enabling one thread to write data and another to read it.This class is part of Java’s inter-thread communication system and works in conjunction with PipedOutputStream. Commonly Used Constructors and Methods Simple Program – Inter-thread Communication Mahesh …

PipedInputStream Read More »

ObjectOutputStream

ObjectOutputStream is used to serialize Java objects—convert them into a byte stream so they can be written to files or sent over a network. It’s the counterpart of ObjectInputStream, which performs deserialization. Commonly Used Constructors and Methods The object being written must implement Serializable interface, or NotSerializableException is thrown. Simple Program – Serializing a Single …

ObjectOutputStream Read More »

ObjectInputStream

ObjectInputStream is used to deserialize objects—that is, to read objects previously written to a stream using ObjectOutputStream. It reconstructs objects, arrays, and primitive data types from an input stream. Commonly Used Constructors and Methods Simple Program – Reading an Object from File Mahesh wants to read a serialized Employee object from a file named employee.ser …

ObjectInputStream Read More »

DataOutputStream

DataOutputStream lets you write Java primitive data types (like int, float, double, char, boolean) to an output stream in a machine-independent way. It’s usually paired with an OutputStream like FileOutputStream or ByteArrayOutputStream. Commonly Used Constructors and Methods Simple Program – Writing Primitives to File Mahesh wants to store LotusJavaPrince‘s employee ID, name, and salary in …

DataOutputStream Read More »

DataInputStream

DataInputStream allows an application to read Java primitive data types (like int, float, char, etc.) from an underlying input stream in a machine-independent way. It’s commonly used with FileInputStream, ByteArrayInputStream, or any stream that provides raw bytes. Commonly Used Constructors and Methods Simple Program – Reading Primitives from File LotusJavaPrince stores his profile info using …

DataInputStream Read More »

ByteArrayOutputStream

ByteArrayOutputStream is a memory-based stream that collects output data in an internal byte array. It’s useful when you want to build a byte array dynamically (e.g., generating PDF content, processing images, etc.).It automatically resizes its internal buffer as data is written. Commonly Used Constructors and Methods Simple Program – Writing and Printing Byte Array LotusJavaPrince …

ByteArrayOutputStream Read More »

ByteArrayInputStream

ByteArrayInputStream allows an application to read data from a byte array as if it were an input stream. It is especially useful for simulating input for testing or for reading memory-stored data byte-by-byte. Commonly Used Constructors and Methods Simple Program – Reading from ByteArrayInputStream LotusJavaPrince wants to read a byte array “Hello, Mahesh” using ByteArrayInputStream …

ByteArrayInputStream Read More »

Scroll to Top