//package com.nowjava;
public class Main {
/*来自
时 代 J a v a 公 众 号 - N o w J a v a . c o m*/
public static void main(String[] argv) throws Exception {
byte[] array = new byte[] { 34, 35, 36, 37, 37, 37, 67, 68, 69 };
int newLength = 2;
System.out.println(java.util.Arrays.toString(truncate(array,
newLength)));
}
/**
* Truncates the given array to the request length.
*
* @param array
* the array to be truncated.
* @param newLength
* the new length in bytes.
* @return the truncated array.
*/
public static byte[] truncate(byte[] array, int newLength) {
if (array.length < newLength) {
return array;
} else {
byte[] truncated = new byte[newLength];
/**代码未完, 请加载全部代码(NowJava.com).**/
本文系作者在时代Java发表,未经许可,不得转载。如有侵权,请联系nowjava@qq.com删除。