DataInputStream.read(byte[] b, int off, int len) has the following syntax.
public final int read(byte[] b, int off, int len) throws IOException
In the following code shows how to use DataInputStream.read(byte[] b, int off, int len) method.
import java.io.DataInputStream; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; //from w w w.jav a2s. c om public class Main { public static void main(String[] args) throws IOException { InputStream is = new FileInputStream("c:\\test.txt"); DataInputStream dis = new DataInputStream(is); int count = is.available(); byte[] bs = new byte[count]; dis.read(bs, 4, 3); for (byte b : bs) { char c = (char) b; if (b == 0){ c = '0'; } System.out.print(c); } } }