我一直在嘗試讀取一個txt文件。 TXT文件包含的行e.g讀取txt文件內容並存儲在數組中
First Line
Second Line
Third Line
.
.
.
現在,我使用下面的代碼
InputStream is = null;
try {
is = getResources().getAssets().open("myFile.txt");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
ArrayList<String> arrayOfLines = new ArrayList<String>();
Reader reader;
//char[] buffer = new char[2048];
try {
Reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
int n;
while ((n = reader.read()) != -1) {
}
}catch (Exception e) {
e.printStackTrace();
}
我的問題是,我怎麼能存儲在ArrayList中的每一行。 Ofc我們必須使用支票"/n"
但是如何。
它存儲的話不僅沒有全線。 – 2012-08-12 00:27:58
我的錯誤。檢查編輯。 – Makoto 2012-08-12 00:28:48