StringWriter StringWriter is a character stream that collects its output in a string buffer, which can then be used to construct a string. Closing a StringWriter has no effect. The methods in this class can be called after the stream has been … Continued
RandomAccessFile A random access file behaves like a large array of bytes stored in the file system. There is a kind of cursor, or index into the implied array, called the file pointer; input operations read bytes starting at the file … Continued
try – catch: Aspects that make Java exception handling( try catch ) different: An object that’s used for throwing in Java must of type that is a subclass of Throwable. By convention, however, user-defined exceptions are of type Exception, a subclass of Throwable. … Continued
Bubble Sort Bubble sort is one of the classic sorting algorithms, because of its algorithmic nature and simplicity it’s often used in various Java applications. In Bubble sort algorithm we sort an unsorted array by starting from first element and comparing with … Continued
FileReader FileReader is a convenient class for reading character files. The constructors of this class assume that the default character encoding and the default byte-buffer size are appropriate. To specify these values yourself, construct an InputStreamReader on a FileInputStream. FileReader is … Continued
Binary Search in Java: Binary search requires a sorted collection. The advantage of a Binary search over a linear search is used for large numbers. It can be done either recursively or iteratively. In the given code, we have allowed … Continued
PipedWriter:— The Java.io.PipedWriter piped character-output streams. Syntax for PipedWriter Class declaration: The declaration of java.io.PipedWriter class is as follows: public class PipedWriter extends Writer Indexes of PipedWriter: There … Continued
An OutputStreamWriter is a bridge from character streams to byte streams: Characters written to it are encoded into bytes using a specified charset.
The charset that it uses may be specified by name or may be given explicitly, or the platform’s default charset may be accepted.
Each invocation of a write() method causes the encoding converter to be invoked on the given character(s).
The resulting bytes are accumulated in a buffer before being written to the underlying output stream. The size of this buffer may be specified, but by default it is large enough for most purposes.
Note: The characters passed to the write() methods are not buffered.
LineNumberInputStream class is an input stream filter that provides the added functionality of keeping track of the current line number.
A line is a sequence of bytes ending with a carriage return character (‘\r’), a newline character (‘\n’), or a carriage return character followed immediately by a linefeed character. In all three cases, the line terminating character(s) are returned as a single newline character.
The line number begins at 0, and is incremented by 1 when a read returns a newline character.
FilterWriter class is used for writing filtered character streams. Java.io.FilterWriter class is an abstract class which itself provides default methods that pass all requests to the contained stream.
The Subclasses of FilterWriter should override some of these methods and may also provide additional methods and fields.