标签:exce buffered public style class 写入 als buffer 入行
1 import java.io.BufferedReader; 2 import java.io.File; 3 import java.io.FileReader; 4 import java.io.FileWriter; 5 import java.io.PrintWriter; 6 import java.util.Scanner; 7 8 public class F1_F2_copy { 9 10 public void F1_F2(File f1,File f2) 11 { 12 try 13 { 14 15 int i=1; 16 //写入f2 17 FileWriter fw=new FileWriter(f2,false); 18 PrintWriter pw=new PrintWriter(fw); 19 //阅读f1 20 Scanner shuru = new Scanner(new BufferedReader(new FileReader(f1))); 21 while(shuru.hasNext()) 22 { 23 pw.println(i+" "+shuru.next());//插入行号 24 i++; 25 } 26 27 pw.flush(); 28 pw.close(); 29 fw.close(); 30 31 32 } 33 catch(Exception e) 34 { 35 System.out.println("错误"); 36 } 37 38 } 39 }
对一个空文本复制一个有行号的文本
标签:exce buffered public style class 写入 als buffer 入行
原文地址:https://www.cnblogs.com/gonT-iL-evoL-I/p/9981359.html