Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

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

public class Main {
    public static void main(String[] args) throws Exception {
        InputStream inStream = new FileInputStream("c:/test.txt");

        BufferedInputStream bis = new BufferedInputStream(inStream);

        // read number of bytes available
        int numByte = bis.available();

        // byte array declared
        byte[] buf = new byte[numByte];

        // read byte into buf , starts at offset 2, 3 bytes to read
        bis.read(buf, 2, 3);

        // for each byte in buf
        for (byte b : buf) {
            System.out.println((char) b + ": " + b);
        }
    }
}