由网友(久安)分享简介:搞不明白怎么算行。这是我的code。Can't understand how to count lines. Here is my code.void load() throws IOException { File sdcard = Environment.getExternalSto...
搞不明白怎么算行。这是我的code。
Can't understand how to count lines. Here is my code.
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);
} 那么,如何计算和的setText在TextView中?谢谢!
} So, how to count and settext in TextView? Thank you!
推荐答案
这是你要找的是什么?
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;
TextView te=(TextView)findViewById(R.id.textView1);
int lineCount = 0;
while ((line = br.readLine()) != null) {
text.append(line);
text.append('n');
lineCount++;
}
te.setText(String.valueOf(lineCount));
}
catch (IOException e) {
//You'll need to add proper error handling here
}
Button monpopb = (Button) findViewById(R.id.button13);
monpopb.setText(text);
}
相关推荐
最新文章