输出文档(txt)的行号
2017-03-30 10:06
169 查看
import java.io.*; /** * Created by Administrator on 2017/3/30. */ class LineNum extends BufferedReader{ int count = 1; public LineNum(Reader in) { super(in); } //复写BufferedReader的readLine()方法 @Override public String readLine() throws IOException { String line = super.readLine(); if(line == null){ return null; } line = count + " " + line;//输出:行号 + 一个空格 + 每行的文本 count++; return line; } } public class LineNumTest { public static void main(String[] args) throws IOException { File file = new File("E:\\test.txt");//需要读取的文本 FileReader fileReader = new FileReader(file);//建立读取文本的通道 LineNum lineNum = new LineNum(fileReader);//使用lineNum类 String content = null; while ((content = lineNum.readLine()) != null){ System.out.println(content); } lineNum.close();//关闭数据流 } }
相关文章推荐
- Asp.Net页面输出到WORD、EXCEL、TXT、HTM等类型的文档
- C++ code: 将程序的输出,保存到txt文档中,且每35个数,自动换行
- python jieba分词并统计词频后输出结果到Excel和txt文档
- 把输出内容存到TXT文档
- 把excel每一行中的数据输出为一个txt文档的VBA函数
- 以图形做按钮,输出txt文档
- [转]Asp.Net页面输出到WORD、EXCEL、TXT、HTM等类型的文档
- 编写一个程序,在E盘下创建一个abc.txt的文本文档,通过输出流在文档内添加数据,然后在把abc.txt复制到F盘下
- 对大型矩阵输出到终端和txt文档的方法
- 用python找出两个文档的差异输出行号和列号
- Java入门学习-实践:手动输入城市名称5次,完成后输出一份city.txt文档,写出被输入最多次的城市名字
- Python计算两个日期相差的天数,并输出到txt文档中
- C++输出数据到TXT文档中
- Asp.Net输出指定内容的Word、Excel、TXT、HTM等类型的文档
- 利用ASP.NET输出指定内容的WORD、EXCEL、TXT、HTM等类型的文档
- // 编写一个程序,在E盘下创建一个abc.txt的文本文档,通过输出流在文档内添加数据,然后在把abc.txt复制到F盘下
- windows生成目录结构输出到txt文档
- 利用ASP.NET输出指定内容的WORD、EXCEL、TXT、HTM等类型的文档
- (八十九)txt文档的输入和输出
- 如何将ModelSim仿真输出的数据导入txt文档