本文介绍了转换的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 []的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!