I’m showing an about text from a text file with the following code. But I have problems to show german umlauts ä, ü, ö correctly. How can I change or set the encoding?
Androis says:
public InputStreamReader (InputStream in) Since: API Level 1
Constructs a new InputStreamReader on the InputStream in. This
constructor sets the character converter to the encoding specified in
the “file.encoding” property and falls back to ISO 8859_1
(ISO-Latin-1) if the property doesn’t exist.
public void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.help);
TextView tv = (TextView)findViewById(R.id.help_text);
//tv.setText(readRawTextFile(R.raw.help));
tv.setText(Html.fromHtml(readRawTextFile(R.raw.help)));
}
public static String readRawTextFile(int id) {
InputStream inputStream = mContext.getResources().openRawResource(id);
InputStreamReader in = new InputStreamReader(inputStream);
BufferedReader buf = new BufferedReader(in);
String line;
StringBuilder text = new StringBuilder();
try {
while (( line = buf.readLine()) != null)
text.append(line);
//text.append("<br>" );
} catch (IOException e) {
return null;
}
return text.toString();
}
Thanks in advance!
You can try to specify the charset being used in the text file during the InputStreamReader creation with:
You can find available charsets in: Charset
Good luck.