M
Matthijs Blaas
Hi all!
I have a byte array of data which I want to post to an php script. So I send
the representing string of the byte array using a post with utf-8 encoding.
I figured java works with UTF-16BE internally, but after receiving the utf-8
encoded post in php and converting it to back to UTF-16BE it was not the
same...
I wrote a little test and it turns out if i conver a byte array to utf-8 and
back it wont match the original byte array, but the string representing it
is the same:
String test="some test";
byte[] dest,temp;
dest = test.getBytes();
try {
temp=new String(dest).getBytes("UTF-8");
}catch(Exception e) { System.out.println(e); }
try {
test=new String(temp,"UTF-8");
System.out.println(test);
dest=test.getBytes();
} catch(Exception e) { System.out.println(e); }
if(dest==temp) System.out.println("Success!");
else System.out.println("failed");
How can I convert the UTF-8 bytes back to the original byte array? And will
this work when posting to php? Its important the binary data remains intact
instead of the string representation...
Thanks in advance,
Matthijs
I have a byte array of data which I want to post to an php script. So I send
the representing string of the byte array using a post with utf-8 encoding.
I figured java works with UTF-16BE internally, but after receiving the utf-8
encoded post in php and converting it to back to UTF-16BE it was not the
same...
I wrote a little test and it turns out if i conver a byte array to utf-8 and
back it wont match the original byte array, but the string representing it
is the same:
String test="some test";
byte[] dest,temp;
dest = test.getBytes();
try {
temp=new String(dest).getBytes("UTF-8");
}catch(Exception e) { System.out.println(e); }
try {
test=new String(temp,"UTF-8");
System.out.println(test);
dest=test.getBytes();
} catch(Exception e) { System.out.println(e); }
if(dest==temp) System.out.println("Success!");
else System.out.println("failed");
How can I convert the UTF-8 bytes back to the original byte array? And will
this work when posting to php? Its important the binary data remains intact
instead of the string representation...
Thanks in advance,
Matthijs