Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.io.FileInputStream;
import java.io.InputStream;

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

        InputStream is = new FileInputStream("C://test.txt");

        System.out.println("Characters printed:");
        // create new buffered reader

        // reads and prints BufferedReader
        System.out.println((char) is.read());
        System.out.println((char) is.read());

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

        // reset() repositioned the stream to the mark
        if (is.markSupported()) {
            is.reset();
            System.out.println("reset() invoked");
            System.out.println((char) is.read());
            System.out.println((char) is.read());
        } else {
            System.out.print("InputStream does not support reset()");
        }
        is.close();
    }
}