Let's Go!

java从一个文件读取,写入到另一个文件

上一篇 / 下一篇  2010-03-21 12:50:42 / 个人分类:JAVA学习&编程相关

import java.io.* ;


public class FileCopy {

 /**
  * @param args
  */
 public static void main(String[] args) {
  // TODO Auto-generated method stub
  

  System.out.println("start.....") ;
  
  for(int k =10;k<10000;k++){
  try
  {
   //int i =7;
   File f1 = new File("D:\\upload\\file\\"+"CHNH"+ Integer.toString(k)+".txt");
      
   // 向文件打印字符流:
   PrintWriter pw = new PrintWriter(new FileWriter(f1)) ;
      
   BufferedReader bf = new BufferedReader(new FileReader("D:\\upload\\CHNH06.txt")) ;
   
   String s = "" ;
   //String content = "" ;
   while((s = bf.readLine() )!= null)
   {
     //content = content + s;
     pw.println(s) ;
     pw.flush() ;
    }
      
   pw.close() ;

  }
  catch(Exception e)
  {
   
  }
  
  
  } // for 结束
  
  
  
  
  
  System.out.println("over.....") ;
 }

}


TAG:

 

评分:0

我来说两句

Open Toolbar