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");

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

        // mark is set on the input stream
        is.mark(0);

        System.out.println("Char : " + (char) is.read());
        System.out.println("Char : " + (char) is.read());

        if (is.markSupported()) {
            // reset invoked if mark() is supported
            is.reset();
            System.out.println("Char : " + (char) is.read());
            System.out.println("Char : " + (char) is.read());
        }
        is.close();
    }
}