Constructors in Java Reader Class

There are two constructors used with Java Reader Class as mentioned below:

  • protected Reader(): Creates a new character-stream reader whose critical sections will synchronize on the reader itself.
  • protected Reader(Object lock): Creates a new character-stream reader whose critical sections will synchronize on the given object.

Java.io.Reader class in Java

Java Reader class is an abstract class for reading character streams. The only methods that a subclass must implement are read(char[], int, int), and close(). Most subclasses, however, will override some of the methods defined here in order to provide higher efficiency, additional functionality, or both. 

Similar Reads

Constructors in Java Reader Class

There are two constructors used with Java Reader Class as mentioned below:...

Methods in Java Reader Class

1. abstract void close()...

Example

Java // Java program demonstrating Reader methods import java.io.*; import java.nio.CharBuffer; import java.util.Arrays;    // Driver Class class ReaderDemo {     // Main function     public static void main(String[] args)         throws IOException     {         Reader r = new FileReader(" file.txt & quot;);         PrintStream out = System.out;         char c[] = new char[10];         CharBuffer cf = CharBuffer.wrap(c);            // illustrating markSupported()         if (r.markSupported()) {             // illustrating mark()             r.mark(100);             out.println("                         mark method is supported & quot;);         }         // skipping 5 characters         r.skip(5);            // checking whether this stream is ready to be read.         if (r.ready()) {             // illustrating read(char[] cbuf,int off,int             // len)             r.read(c, 0, 10);             out.println(Arrays.toString(c));                // illustrating read(CharBuffer target )             r.read(cf);             out.println(Arrays.toString(cf.array()));                // illustrating read()             out.println((char)r.read());         }         // closing the stream         r.close();     } }...

Implementation of Reader Classes

...