转换的char []为byte [] [英] Converting char[] to byte[]

查看:159
本文介绍了转换的char []为byte []的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想一个字符数组转换在Java字节数组。制作这种转换存在什么样的方法?


解决方案

 的char [] CH =?
新的String(CH).getBytes();

 新的String(CH).getBytes(UTF-8);

要获得非默认的字符集。

更新:由于Java 7:新的String(CH).getBytes(StandardCharsets.UTF_8);

I would like to convert a character array to a byte array in Java. What methods exists for making this conversion?

解决方案

char[] ch = ?
new String(ch).getBytes();

or

new String(ch).getBytes("UTF-8");

to get non-default charset.

Update: Since Java 7: new String(ch).getBytes(StandardCharsets.UTF_8);

这篇关于转换的char []为byte []的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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