Java 把linux hostname 的byte[]转成String

阅读 177

2022-07-27


byte[] ip =InetAddress.getByName(host)
                                   .getAddress();
String ipStr = new StringBuffer().append(ip[0] & 0xFF)
                                             .append('.')
                                             .append(ip[1] & 0xFF)
                                             .append('.')
                                             .append(ip[2] & 0xFF)
                                             .append('.')
                                             .append(ip[3] & 0xFF)
                                             .toString();

精彩评论(0)

0 0 举报