Java tutorial
import java.io.ByteArrayInputStream; import java.io.IOException; public class Main { public static void main(String[] args) throws IOException { byte[] buf = { 65, 66, 67, 68, 69 }; ByteArrayInputStream bais = new ByteArrayInputStream(buf); byte[] b = new byte[4]; int num = bais.read(b, 2, 2); System.out.println("Bytes read: " + num); for (byte s : b) { char c = (char) s; System.out.println(s); if (s == 0) { System.out.println(": Null"); } else { System.out.println(": " + c); } } } }