1. 字节数组截取
-
方法
- src:源数组
- srcPos:源数组要复制的起始位置
- dest:目的数组
- destPos:目的数组放置的起始位置
- length:要复制的长度
public static native void arraycopy(Object src, int srcPos,Object dest, int destPos,int length);
-
例子
long time = new Date().getTime(); // long类型转换为byte类型 ByteArrayOutputStream bos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(bos); dos.writeLong(time); byte[] bytes1 = bos.toByteArray(); int count = 6; byte[] temp = new byte[count]; // 截取数组后六位 System.arraycopy(bytes1,2,temp,0,count); for (byte b1 : bytes1){ System.out.println(b1); } System.out.println("_______"); for (byte b1 : temp){ System.out.println(b1); }