如何有效地将字节数组转换为字符串

如何有效地将字节数组转换为字符串

问题描述:

我有一个151字节的字节数组,通常是一条记录,需要将记录插入到oracle数据库中。在151字节的数组范围内,从0到1是记录id,2到3是引用id,4到9是日期值。字节数组中的以下数据是日期值。我想将其转换为字符串

I have a byte array of 151 bytes which is typically a record, The record needs to inserted in to a oracle database. In 151 byte of array range from 0 to 1 is a record id , 2 to 3 is an reference id , 4 to 9 is a date value. The following data in an byte array is a date value. i want to convert it to string

byte[] b= {48,48,49,48,48,52};  // when converted to string it becomes 10042. 

new String(b);  // current approach

有没有办法有效地转换某个范围的字节数组( Arrays.copyOfRange(b,0,5))到字符串。

is there any way to efficiently to convert byte array of some range (Arrays.copyOfRange(b,0,5)) to string .

new String(b, 0 ,5);

Gee,谁能猜到?每个打扰看 API doc ,那是谁。

Gee, who could have guessed? Everyone who bothered to look at the API doc, that's who.