用文件类实现复制功能

  1. /*  
  2.  * couter:苏奕祥  
  3.  * 实现两个文件的复制功能并且用到正则表达式替换复制完后的值  
  4.  *   
  5.  */   
  6.   
  7. import  java.io.*;  
  8. import  java.util.regex.Matcher;  
  9. import  java.util.regex.Pattern;  
  10.     public   class  CopyFile {  
  11.         public   static   void  main(String[] args) throws  IOException{  
  12.             File f=new  File( "E:\\sdx.txt" );  
  13.             File f2=new  File( "E:\\sdxcopy.txt" );  
  14.             Writer copy=new  FileWriter(f2);  
  15.                 Writer aaa=null ;  
  16.                 aaa=new  FileWriter(f);  
  17.                 aaa.write("I LOVE U I LOVE U I LOVE U\r\nI LOVE U I LOVE U I LOVE U\r\nI LOVE U I LOVE U I LOVE U" );  
  18.                 aaa.close();  
  19.               
  20.                 Reader read=null ;  
  21.                 read=new  FileReader(f);  
  22.                 char  c[]= new   char [ 1024 ];  
  23.                 int  len=read.read(c);  
  24.                 System.out.println(len);  
  25.         [color=blue][/color]        read.close();  
  26.                 String str=new  String(c, 0 ,len);  
  27.                 System.out.println("内容为:" +str);  
  28.           
  29.             Pattern p=Pattern.compile("LOVE" );  
  30.             Matcher m=p.matcher(str);  
  31.             String str2=m.replaceAll("HATE" );  
  32.             System.out.println(str2);  
  33.             copy.write(str2);  
  34.             copy.close();  
  35.   
  36.           
  37.     }     
  38. }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值