我正在使用以下代码显示来自文本文件的 about 文本。但我无法正确显示德语变音符号ä、ü、ö。如何更改或设置编码?安德罗斯 说:
public InputStreamReader (InputStream in) 自:API Level 1
在 InputStream 中构造一个新的 InputStreamReader。此构造函数将字符转换器设置为“file.encoding”属性中指定的编码,如果该属性不存在,则回退到 ISO 8859_1 (ISO-Latin-1)。
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();
}
提前致谢!