AIIYIIII!!!!

You might want to check the documentation before you make such
statements: 
http://developer.android.com/intl/de/reference/java/lang/String.html#String(byte[])

Do *NOT*, under *ANY* circumstance, omit that second argument.

Just because it works, TODAY, on YOUR device, does not make this
correct programming.

Your conclusion, however, is correct - char-at-a-time conversion
cannot work in all cases, and byte-at-a-time is even worse. You really
do have to treat it as a byte stream. Just make sure you nail down the
encoding of that byte stream.

For more on this, see the last few items on my blog:

http://bobkerns.typepad.com/bob_kerns_thinking/2010/12/yet-more-about-utf-8-the-evils-of-platform-defaults.html

In addition to that article, note the subsequent link to the Oracle
site. Among many other topics, that article discusses the new (as of
Java 5) APIs to handle conversion of surrogate characters properly,
and this is an area where char-at-a-time encoding fails.

On Dec 1, 4:51 pm, HippoMan <[email protected]> wrote:
> I should clarify that I now don't need to do this:
>
>     String content = new String(bytes, "UTF-8");
>
> This is because java's default is unicode. I get the same result with
> or without the second argument to the String constructor.
>
> I now see that my original error resulted because I was converting to
> individual chars and appending them one-by-one, instead of dealing
> with a mass of bytes, which then could have been properly converted to
> unicode.

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to