如何有效地将字节数组转换为字符串 [英] How to efficiently convert byte array to string

查看:116
本文介绍了如何有效地将字节数组转换为字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个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.

这篇关于如何有效地将字节数组转换为字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆