0
我在SDcard上有一個文件 - 「file.txt」包含單獨行中的電話號碼。 我想先顯示行,然後如果我按下按鈕,第二行應顯示在TextView中,第一行應該消失。 我有代碼,只是讀取txt文件的內容,並在TextView中完全插入所有行:我怎樣才能得到.txt文件逐行讀取
當按下按鈕時,應如何將此代碼更改爲串行輸出以下行?
File sdcard = Environment.getExternalStorageDirectory();
File file = new File(sdcard,"file.txt");
StringBuilder text = new StringBuilder();
try {
BufferedReader br = new BufferedReader(new FileReader(file));
String line;
while ((line = br.readLine()) != null) {
line = br.readLine();
text.append(line);
text.append('\n');
}
}
catch (IOException e) {
}
tv.setText(text);
當按下按鈕時,應如何將此代碼更改爲串行輸出以下行?