Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.io.FilterReader;
import java.io.IOException;
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) {
        };

        // reads and prints FilterReader
        System.out.println((char) fr.read());
        System.out.println((char) fr.read());

        // mark invoked at this position
        fr.mark(0);
        System.out.println("mark() invoked");
        System.out.println((char) fr.read());
        System.out.println((char) fr.read());

        // reset() repositioned the stream to the mark
        fr.reset();
        System.out.println("reset() invoked");
        System.out.println((char) fr.read());
        System.out.println((char) fr.read());

    }
}