Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / May 2006

Tip: Looking for answers? Try searching our database.

Convert byte[] to String

Thread view: 
IveCal - 17 May 2006 03:26 GMT
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.



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.