Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        char[] cbuf = new char[5];

        FileInputStream fis = new FileInputStream("C:/test.txt");
        InputStreamReader isr = new InputStreamReader(fis);

        // reads into the char buffer
        int i = isr.read(cbuf, 2, 3);

        // prints the number of characters
        System.out.println("Number of characters read: " + i);

        // for each character in the character buffer
        for (char c : cbuf) {
            // for empty character
            if (((int) c) == 0)
                c = '-';

            System.out.println(c);
        }
        isr.close();
    }
}