I am currently using UTF8 encoding between string and byte[] (and vice versa).
This is done [in c#, but you should get the general idea :)] using;
using System.Text;
public static String changeValue(byte[] msg)
{
String myMsg = "";
char[] msgAsChars = System.Text.Encoding.UTF8.GetChars(byte[] msg);
//now should be a char array of your values
for(int i=0;i<msgAsChars.Length;i++)
{
//loop through your char array and add to string
myMsg +=msgAsChars[i];
}
return myMsg;
}
Might be a bit messy, but you should be able to get the idea.
EDIT
In java; decoding a byte array should be similar to:
String decoded = new String(bytes, "UTF-8");
Or something like:
to convert directly to String, you can always use
`String str = new String(byte[] byteArray);`
EDIT 2
public class Main {
/*
* This method converts a byte array to a String object.
*/
public void convertByteArrayToString() {
byte[] byteArray = new byte[] {87, 79, 87, 46, 46, 46};
String value = new String(byteArray);
System.out.println(value);
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
new Main().convertByteArrayToString();
}
}