Java IO Tutorial - Java[] b, int off, int len)

Syntax[] b, int off, int len) has the following syntax.

public int read(byte[] b, int off, int len)  throws IOException


In the following code shows how to use[] b, int off, int len) method.

/*from   w w w.  j a va2 s .c o m*/

public class Main {
  public static void main(String[] args) throws IOException {

    byte[] bs = new byte[4];
    FileInputStream fis = new FileInputStream("C://test.txt");

    // read bytes to the buffer
    int i =, 2, 1);

    System.out.println("Number of bytes read: " + i);
    // for each byte in buffer
    for (byte b : bs) {
      // converts byte to character
      char c = (char) b;
      if (b == 0){
        c = '-';