0

需要解析这个文件(混合拉丁语和阿拉伯语):

1|حِيمِ
2|الَمِينَ

该文件在记事本++中保存为UTF8,并放在android资产文件夹中。
预期结果:对于第 1 行,条目为“1”和“حِيمِ”(由“|”分隔)。

        AssetManager manager = context.getAssets();
        InputStream inStream = null;
        inStream = manager.open("file.txt");
        BufferedReader buffer = new BufferedReader(new InputStreamReader(inStream, "UTF-8"));
        String line = "";
        while ((line = buffer.readLine()) != null) {
            String lineEnc = URLEncoder.encode(line, "UTF-8");
            String[] columns = lineEnc.split("%7C");
            if (columns.length>=3) {
                Toast toast = Toast.makeText(context, "Line: " + columns[0] + " and " + columns[1], Toast.LENGTH_LONG);
                toast.show();
            }
        }

实际结果:
columns[0] = "1" ok,但
columns[1] = "%D8%AD%D9..." not Ok,预期为 "حِيمِ"。
如何解决这个问题,或者有更好的方法吗?请帮忙。提前致谢。

4

1 回答 1

0

解决,改变:

    while ((line = buffer.readLine()) != null) {
        String lineEnc = URLEncoder.encode(line, "UTF-8");
        String[] columns = lineEnc.split("%7C");

进入

    while ((line = buffer.readLine()) != null) {
        String[] columns = line.split("\\|");
于 2016-01-22T10:22:24.917 回答