I call a webservice, that gives me back a response xml that has UTF-8 encoding. I checked that in java using getAllHeaders()
method.
Now, in my java cod
There are two things:
You should not be preoccupied with the second point ;) The thing is to use the appropriate methods to convert from your data (byte arrays) to String
s (char
arrays ultimately), and to convert form String
s to your data.
The most basic classes you can think of are CharsetDecoder and CharsetEncoder. But there are plenty others. String.getBytes()
, all Reader
s and Writer
s are but two possible methods. And there are all static methods of Character
as well.
If you see gibberish at some point, it means you failed to decode or encode from the original byte data to Java strings. But again, the fact that Java strings use UTF-16 is not relevant here.
In particular, you should be aware that when you create a Reader
or Writer
, you should specify the encoding; if you fail to do so, the default JVM encoding will be used, and it may, or may not, be UTF-8.