有人可以告诉我为什么奇怪的字符不会出现在 Android listView 中吗?
我有一个文本文件
我得到了这个
这是我的代码
ArrayList<String> list = new ArrayList<String>();
InputStream inStream = getResources().openRawResource(R.raw.emoticons);
InputStreamReader inputReader = null;
if (inStream != null)
{
try {
inputReader = new InputStreamReader(inStream, "UTF-8");
}catch (UnsupportedEncodingException e){
e.printStackTrace();
}
int c, i=0;
//int i=0;
char [] cb = new char[1];
byte [] buf = new byte[100];
String line = "";
int ble = -1;
try {
ble = inputReader.read(cb, 0, 1);
}catch (IOException e){
e.printStackTrace();
}
while (ble > -1)
{
if(cb[0] == '\r' || cb[0] == '\n')
{
try{
line = new String(buf, 0, i, "UTF-8");
}catch (UnsupportedEncodingException e){
e.printStackTrace();
}
i=0;
list.add(line);
}
else
{
buf[i++] = (byte) cb[0];
}
try {
ble = inputReader.read(cb, 0, 1);
}catch (IOException e){
e.printStackTrace();
}
}
}
String[] emoticons = list.toArray(new String[list.size()]);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, emoticons);
listview.setAdapter(adapter);