02.12.2010 13:47, HippoMan пишет:
This begs another, related question: how do I know what encoding to
use, in the first place ... for a TextView in the Android environment?
You don't. This is not a TextView encoding issue.
TextView works with Java strings, which are always Unicode.
If I cannot count on the file.encoding property to always be set
correctly when using a TextView in Android, where do I query for the
correct encoding value?
The issue arose when constructing a Java String from a byte array.
As Bob pointed out, that's where you need to specify the encoding, (by
always using the second argument to String(byte[], String)).
The encoding used here needs to match the encoding that was used to
construct the byte array (first argument).
If those bytes came from a file, then you should somehow know the encoding.
Some Unicode files start with a marker (0xFEFF or 0xFFFE), but checking
for this marker isn't reliable and shouldn't be necessary.
Here is some code that is a little more simple that using your own byte
array:
InputStream stream = ..... can be a file input stream
InputStreamReader streamReader = new InputStreamReader(stream, "UTF-8");
BufferedReader textReader = new BufferedReader(streamReader );
// read from textReader
--
Kostya Vasilyev -- WiFi Manager + pretty widget -- http://kmansoft.wordpress.com
--
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