Java记事本 显示行号
发布网友
发布时间:2022-10-01 14:09
我来回答
共1个回答
热心网友
时间:2024-12-05 08:30
读取每行,行头添加行号后显示
BufferedReader input = new BufferedReader(new FileReader(file));
StringBuffer strbuf = new StringBuffer();
String line = input.readLine();
int num = 1;
while (line != null) {
strbuf.append(num);
strbuf.append(line);
strbuf.append('\n');
line = input.readLine();
num++;
}
txaWord.setText(strbuf.toString());