Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.io.FilterReader;
import java.io.Reader;
import java.io.StringReader;

public class Main {
    public static void main(String[] args) throws Exception {

        Reader r = new StringReader("ABCDEF");

        // create new filter reader
        FilterReader fr = new FilterReader(r) {
        };

        // read and print characters one by one
        System.out.println("Char : " + (char) fr.read());
        System.out.println("Char : " + (char) fr.read());
        System.out.println("Char : " + (char) fr.read());

        // mark is set on the filter reader
        fr.mark(0);
        System.out.println("Char : " + (char) fr.read());
        System.out.println("reset() invoked");

        // reset is called
        fr.reset();

        // read and print characters
        System.out.println("char : " + (char) fr.read());
        System.out.println("char : " + (char) fr.read());

    }
}