package com.file;
import java.io.*;
public class LineNumberTwo {
public static void main(String[] args) throws IOException{
LineNumberTwo lineNumberTwo=new LineNumberTwo();
lineNumberTwo.copy("d:/zuoye.txt","d:/zuoye4.txt");
}
private void copy(String src,String des) throws IOException {
BufferedReader br=new BufferedReader(new InputStreamReader(new FileInputStream(src)));
BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(new FileOutputStream(des)));
String emp="";
int i=1;
while ((emp=br.readLine())!=null){
bw.write(i+","+emp);
bw.newLine();
i++;
}
bw.flush();
}
}
I/O流:通过字节流转换为字符流读取输出文本并添加行号
最新推荐文章于 2022-09-07 00:02:24 发布