我正在使用以下代码显示文本文件中的关于文本。但我无法正确显示德语变音符号 ä、ü、ö。如何更改或设置编码? 安德鲁斯说:
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();
}
提前致谢!
最佳答案
您可以尝试在 InputStreamReader 创建期间指定文本文件中使用的字符集:
InputStreamReader in = new InputStreamReader(inputStream, charset);
您可以在以下位置找到可用的字符集:Charset
祝你好运。
关于android - 更改 file.encoding 以显示变音符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12759817/