Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Converting byte into String

Status
Not open for further replies.

firelex

Programmer
Jan 10, 2002
118
DE
Hello, all!
I'm a newbie in JAVA, can anyone tell me how can a byte[] be converted into String?
The situation is:

... somewhere ....
tst=new String(qwertz);
somemethod(tst.getBytes()) ;
..............................

public void somemethod(byte[] oid)
{
String tmp;

tmp=new String();
tmp=oid.toString();
System.out.println("TEST : " + tmp2);
}
This thing gives me the same as "System.out.println("TEST : " + oid);" How could I get the original string "qwertz" back?

Thanks
 
Well, it was perhaps a stupid question ... :((
But I've found the answer myself and for the case, that someone else the same problem has, I'll put it down :

It is possible to make a String from bytes by inserting these bytes into the constructor of String. In my case the answer was :
[tt]
public void somemethod(byte[] oid)
{
String tmp;

tmp=new String(oid);
System.out.println("TEST : " + tmp);
}
[/tt]
This gives the String back, that has been converted into bytes
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top