用的BufferedReader阅读文本文件添加一个空格,机器人 [英] Reading text file with bufferedReader adds a whitespace, android

查看:299
本文介绍了用的BufferedReader阅读文本文件添加一个空格,机器人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的方法来从一个文本文件中的ArrayList

I have this method to get an arrayList from a text file:

private ArrayList<String[]> tempList(){
        String temp = null;
        ArrayList<String[]> tempList = new ArrayList<String[]>();
        try {
            BufferedReader bReader = new BufferedReader(new InputStreamReader(getAssets().open(getFilename())));
            while ((temp = bReader.readLine()) !=null){
            String[] value = temp.split(",");
                tempList.add(value);

            }
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return tempList;
    }

该文件具有只是逗号,没有空格或空行分隔字母。问题是,不知何故该列表的第一个字母在前面有一个空格。其他所有的字母都很好。

The file has just letters separated by comma with no space or empty lines. The problem is that somehow the first letter of the list has a whitespace in front of it. All other letters are fine.

下面是包含本地字母txt文件:

here is the txt file which contains a local alphabet:

Α,Β,Γ
Δ,Ε,Ζ
Η,Θ,Ι
Κ,Λ,Μ
Ν,Ξ,Ο
Π,Ρ,Σ
Τ,Υ,Φ
Χ,Ψ,Ω

任何想法有什么不好?

Any idea what is wrong?

推荐答案

它的可能的是一个零宽度的空间,一个BOM,'\\ uFEFF通常用作第一个字符(由Windows下的记事本),以纪念统一code文件本身。因此,Windows可以UTF-8和当地正常ANSI之间distringuish。

It could be a zero-width space, a BOM, '\uFEFF' normally used as first char (by NotePad under Windows) to mark Unicode files as such. So Windows can distringuish between UTF-8 and normal local ANSI.

如果编辑的第一行被复制,事后字符编码的转换过程中发生的,这将是解释。

If during editing the first line was copied, and afterwards a conversion of character encoding took place, that would be the explanation.

temp = temp.replace("\uFEFF", "");

在一般这种去除BOM是一个不错的主意。

In general this removal of BOM is a good idea.

这篇关于用的BufferedReader阅读文本文件添加一个空格,机器人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆