Skip to content Skip to sidebar Skip to footer

Reading Text File With BufferedReader Adds A Whitespace, Android

I have this method to get an arrayList from a text file: private ArrayList tempList(){ String temp = null; ArrayList tempList = new

Solution 1:

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", "");

In general this removal of BOM is a good idea.


Solution 2:

Just do a little change in your code as suggested from @user3505725 :

String[] value = temp.trim().split(",");

Hope this will help.


Post a Comment for "Reading Text File With BufferedReader Adds A Whitespace, Android"