Java在UTF-16上编码Charset
您能帮助我吗,我可以在UTF-16“测试”输出0074 0065 0073 0074上对Java中的Charset进行编码,对此有一些功能吗?
String x = "test";
System.out.println(x);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Java的标准方法将是方法
getBytes(charset Charset)
classstring
的。为了证明我刚刚写了一个小方法:该方法的输出是:
请注意,值116、101、115、116是十进制值,如果转换为十六进制,则为74、65、73和74-这就是您正在寻找。类
StringunicodeCoderDecoder
您在我的代码中看到的,这为您提供了输出\ u0074 \ u0065 \ u0073 \ u0073 \ u0074
不是标准Java的一部分。它是我写的开源Mgntutils库的一部分。但是在这种情况下,这对您可能非常有用。这是在这里 a href =“ https://github.com/michaelgantman/mgnt/releases” rel =“ nofollow noreferrer”> github 作为JAR(包括源代码和Javadoc),这是一个修改的代码
:是:
The standard method of Java would be method
getBytes(Charset charset)
of classString
. To demonstrate I just wrote a small method:And the output of that method is:
Note that values 116, 101, 115, 116 are decimal values which if converted to Hex would be 74, 65, 73, and 74 - which is what you are looking for. The class
StringUnicodeEncoderDecoder
that you see in my code and that gives you the output\u0074\u0065\u0073\u0074
is not part of a standard Java. It is part of an Open Source MgntUtils library written by me. But it could be very useful to you in this case. Here is the Javadoc for the class StringUnicodeEncoderDecoder. The library itself could be obtained as Maven artifacts from here or from Github as a jar (including source code and Javadoc)Here is a modified code:
And the output would be: