gpt4 book ai didi

android - 如何计算文件txt android中的行数

转载 作者:行者123 更新时间:2023-11-29 18:07:17 28 4
gpt4 key购买 nike

无法理解如何计算行数。这是我的代码。

 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中统计和设置文本呢?谢谢你!

最佳答案

这是您要找的吗?

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);
}

关于android - 如何计算文件txt android中的行数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12749655/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com