?
Solved

Java Question: Taking Input String - Converting to byte[] - now I need to convert byte[] back to the input string?

Posted on 2009-04-18
3
Medium Priority
?
321 Views
Last Modified: 2012-05-06
I have an input str, that I convert to a byte[], and now i need to convert the byte[] back to the original input string.  How is that best accomplished?
0
Comment
Question by:mtitania
  • 2
3 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 24175457
String s = new String(bytes)
0
 
LVL 92

Accepted Solution

by:
objects earned 2000 total points
ID: 24175469
String has a constructor for that

byte[] bytes = s.getBytes();
String s = new String(bytes);

or if a different encoding is used

String s = new String(bytes, charset)
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 24277117
mtitania, can you tell me why you accepted an answer that was just a repeat of mine?

http://www.experts-exchange.com/Programming/Languages/Q_24353926.html#a24231257
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses
Course of the Month16 days, 8 hours left to enroll

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question