Java tutorial
//package com.java2s; import java.util.Arrays; public class Main { public static byte[] subByteArray(byte[] src, int startPos, int num) { int endPos = 0; if (startPos + num > src.length) { endPos = src.length; } else { endPos = startPos + num; } return Arrays.copyOfRange(src, startPos, endPos); } }