Chinaunix首页 | 论坛 | 博客
  • 博客访问: 322632
  • 博文数量: 69
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 759
  • 用 户 组: 普通用户
  • 注册时间: 2014-09-09 14:15
个人简介

〆 人生就是拼命地奔跑,和华丽的跌倒。 つ

文章分类

全部博文(69)

文章存档

2017年(2)

2016年(16)

2015年(21)

2014年(30)

分类: Java

2017-07-06 20:43:33


点击(此处)折叠或打开

  1. package com.itheima;

  2. import java.io.BufferedReader;
  3. import java.io.BufferedWriter;
  4. import java.io.FileReader;
  5. import java.io.FileWriter;
  6. import java.io.IOException;

  7. public class BufferedStreamDemo3 {
  8.     public static void main(String[] args) throws IOException {
  9.         String srcFileName = "FileWriterDemo.txt";
  10.         String destFileName = "Copy.txt";
  11.         
  12. //        method1(srcFileName,destFileName);
  13. //        method2(srcFileName,destFileName);
  14. //        method3(srcFileName,destFileName);
  15. //        method4(srcFileName,destFileName);
  16. //        method5(srcFileName,destFileName);

  17.     }
  18.     public static void method5(String srcFileName,String destFileName) throws IOException {
  19.         
  20.         BufferedReader br=new BufferedReader(new FileReader(srcFileName)) ;
  21.         BufferedWriter bw=new BufferedWriter(new FileWriter(destFileName)) ;
  22.         
  23.         
  24.         String leng;
  25.         while((leng = br.readLine())!=null)
  26.         {
  27.             bw.write(leng);
  28.             bw.newLine();
  29.             bw.flush();
  30.         }
  31.         bw.close();    
  32.         br.close();
  33.     }
  34.     
  35.     public static void method4(String srcFileName,String destFileName) throws IOException {
  36.             
  37.         BufferedReader br=new BufferedReader(new FileReader(srcFileName)) ;
  38.         BufferedWriter bw=new BufferedWriter(new FileWriter(destFileName)) ;
  39.         
  40.         char[] ch = new char[1024];
  41.         int len;
  42.         while((len = br.read(ch))!=-1)
  43.         {
  44.             bw.write(ch,0,len);
  45.         }
  46.         bw.close();    
  47.         br.close();
  48.     }
  49.     
  50.     public static void method3(String srcFileName,String destFileName) throws IOException {
  51.             
  52.         BufferedReader br=new BufferedReader(new FileReader(srcFileName)) ;
  53.         BufferedWriter bw=new BufferedWriter(new FileWriter(destFileName)) ;
  54.         
  55.         int ch;
  56.         while((ch = br.read())!=-1)
  57.         {
  58.             bw.write(ch);
  59.         }
  60.         bw.close();    
  61.         br.close();
  62.     }
  63.     
  64.     
  65.     public static void method2(String srcFileName,String destFileName) throws IOException {
  66.         
  67.         FileReader fr = new FileReader(srcFileName);
  68.         FileWriter fw = new FileWriter(destFileName);
  69.         
  70.         char[] ch = new char[1024];
  71.         int len;
  72.         while((len = fr.read(ch))!=-1)
  73.         {
  74.             fw.write(ch,0,len);
  75.         }
  76.         fw.close();    
  77.         fr.close();
  78.     }
  79.     
  80.     public static void method1(String srcFileName,String destFileName) throws IOException {
  81.         
  82.         FileReader fr = new FileReader(srcFileName);
  83.         FileWriter fw = new FileWriter(destFileName);
  84.         
  85.         int ch;
  86.         while((ch = fr.read())!=-1)
  87.         {
  88.             fw.write(ch);
  89.         }
  90.         fw.close();    
  91.         fr.close();
  92.     }
  93. }
阅读(2192) | 评论(0) | 转发(0) |
0

上一篇:HTML5--form元素

下一篇:MyStudentManger_io

给主人留下些什么吧!~~