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];

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

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

        // read stream data into buffer
        is.read(buffer, 2, 3);

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

            // convert byte to character
            if (b == 0)// if b is empty
                c = '-';
            else
                c = (char) b;// if b is read
            System.out.print(c);
        }
        is.close();
    }
}