Java IPv6地址字符串到字节 [英] Java IPv6 Address String to Bytes
本文介绍了Java IPv6地址字符串到字节的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何将包含ipv6的机器包目的地的字符串转换为16字节的数组?我知道getBytes和编码,但我似乎不了解我应该使用哪个编码,或者我必须将该字符串转换为十六进制。
How can I convert a String containing the ipv6's machine packet destination to a 16 byte array? I know about getBytes and encodings, but I can't seem to understand which encoding I should use or if I have to convert that String to Hexadecimal or not.
String ipv6 = "2001:0DB8:AC10:FE01:0000:0000:0000:0000";
byte[] bytes = ipv6.getBytes(); //must be a 16 byte array
我想做的一个例子,只是为了举例说明。
Obs .:我必须将String转换为16字节数组
谢谢
An example of what I wanna do, just to exemplify. Obs.: I have to convert the String to a 16 byte array Thanks
推荐答案
尝试这个
InetAddress a = InetAddress.getByName("2001:0DB8:AC10:FE01:0000:0000:0000:0000");
byte[] bytes = a.getAddress();
这篇关于Java IPv6地址字符串到字节的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文