LineNumberReader的简单使用案例
- import java.io.*;
- class TestLineNumber
- {
- public static void main(String[] args) throws IOException
- {
- LineNumberReader lr = new LineNumberReader(new FileReader("Fileread.java"));
- BufferedWriter bw=new BufferedWriter(new FileWriter("numfile.txt"));
- //lr.setLineNumber(1);
- String len = null;
- while((len=lr.readLine())!=null)
- {
- bw.write(lr.getLineNumber()+": "+len);
- bw.flush();
- bw.newLine();
- }
- lr.close();
- bw.close();
- }
- }
复制代码
|
|