Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.io.FileReader;
import java.io.IOException;
import java.io.LineNumberReader;

public class Main {
    public static void main(String[] args) throws IOException {
        // create new reader
        FileReader fr = new FileReader("C:/test.txt");
        LineNumberReader lnr = new LineNumberReader(fr);

        // reads and prints data from reader
        System.out.println((char) lnr.read());
        System.out.println((char) lnr.read());

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

        // if this reader supports mark() an reset()
        if (lnr.markSupported()) {
            // reset() repositioned the reader to the mark
            lnr.reset();
            System.out.println("reset() invoked");
            System.out.println((char) lnr.read());
            System.out.println((char) lnr.read());
        }
        lnr.close();
    }
}