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 {

        byte[] buffer = new byte[5];

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

        System.out.println("Characters printed:");

        // read stream data into buffer
        is.read(buffer);

        // for each byte in the buffer
        for (byte b : buffer) {
            // convert byte to character
            char c = (char) b;

            // prints character
            System.out.print(c);
        }
        is.close();
    }
}