android - 更改 file.encoding 以显示变音符号

标签 android

我正在使用以下代码显示文本文件中的关于文本。但我无法正确显示德语变音符号 ä、ü、ö。如何更改或设置编码? 安德鲁斯说:

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/

相关文章:

java - 如何在 execSQL() 中使用变量?

使用协程执行的 Android kotlin 任务

android - 无法解析符号 FacebookSdk

javascript - 使用 getUserMedia() 读取二维码

android - 如何将 ALSA 与 android ndk 一起使用?

android - Unreal 中的受限文件夹名称

使用 OpenGL ES 2.0 的 Android 绘图纹理在某些设备上运行缓慢

android - 如何在 android 仪器测试中停止和重新启动 Activity ?

java - 从 Android 中的 URL 解析极其简单的 JSON

android - Reactnative $JAVA_HOME 路径错误