無法理解如何計算行數。這是我的代碼。如何計算文件txt中的行android
void load() throws IOException
{
File sdcard = Environment.getExternalStorageDirectory();
File file = new File(sdcard,"agenda.file");
StringBuilder text = new StringBuilder();
try {
BufferedReader br = new BufferedReader(new FileReader(file));
String line;
while ((line = br.readLine()) != null) {
text.append(line);
text.append('\n');
TextView te=(TextView)findViewById(R.id.textView1);
}
}
catch (IOException e) {
//You'll need to add proper error handling here
}
Button monpopb = (Button) findViewById(R.id.button13);
monpopb.setText(text);
} 那麼,如何計算和TextView中的setText?謝謝!
因此,您正在讀取行,在while循環中遞增計數器有什麼問題? – njzk2
另外,TextView在while循環中做了什麼? – njzk2
是的,這是我的錯誤 – yota9