我必須讀取包含一行字符串的dict.txt文件,並將這些字符串添加到數組列表中。將InputStream讀取到Arraylist
我嘗試這樣做:
public ArrayList<String> myDict = new ArrayList<String>();
InputStream is = (getResources().openRawResource(R.raw.dict));
BufferedReader r = new BufferedReader(new InputStreamReader(is));
try {
while (r.readLine() != null) {
myDict.add(r.readLine());
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
但蹊蹺的...
你第二次閱讀兩次同時添加到列表中。 – 2011-12-16 09:14:24