Here is the code snippet. Can somebody help me convert byte arrays to
String? Here is the code snippet:
InetAddress addr = InetAddress.getLocalHost();
byte[] ipAddr = addr.getAddress();
How will I convert byte[] ipAddr to String . . . ?
Please do reply . . .
Thanks . . .
JScoobyCed - 17 May 2006 03:53 GMT
> Here is the code snippet. Can somebody help me convert byte arrays to
> String? Here is the code snippet:
[quoted text clipped - 5 lines]
> Please do reply . . .
> Thanks . . .
Errr...
String strIP = new String(ipAddr);
Is it what you mean?

Signature
JSC
Alan Krueger - 17 May 2006 04:24 GMT
> Here is the code snippet. Can somebody help me convert byte arrays to
> String? Here is the code snippet:
[quoted text clipped - 3 lines]
>
> How will I convert byte[] ipAddr to String . . . ?
http://javaalmanac.com/egs/java.net/ResolveHostname.html ?
Dale King - 17 May 2006 04:46 GMT
> Here is the code snippet. Can somebody help me convert byte arrays to
> String? Here is the code snippet:
[quoted text clipped - 3 lines]
>
> How will I convert byte[] ipAddr to String . . . ?
You don't. InetAddress has a method (poorly named) to return the raw IP
address as a string:
String addressString = addr.getHostAddress();
You don't want to do the conversion yourself because some day you may be
dealing with IPV6 addresses which are 128-bit and do not use dots. If
you use the method above you will work with IPV4 and IPV6 and whatever
comes along after that.

Signature
Dale King
Alan Krueger - 17 May 2006 05:31 GMT
> You don't want to do the conversion yourself because some day you may be
> dealing with IPV6 addresses which are 128-bit and do not use dots. If
> you use the method above you will work with IPV4 and IPV6 and whatever
> comes along after that.
Good point about the IPv6 addresses. Lots of colons and not so many dots.
Roedy Green - 24 May 2006 01:41 GMT
>Here is the code snippet. Can somebody help me convert byte arrays to
>String? Here is the code snippet:
see http://mindprod.com/jgloss/conversion.html

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.