缓冲字符流

package New_IO;

import java.io.*;

/**

  • 缓冲字符流
    */
    public class Test3 {
    public static void main(String[] args) {
    try {
    // Test3.testBuffereReader(“F:\Java_project_new\src\New_IO\tt.txt”);
    // Test3.testBuffereWriter(“F:\Java_project_new\src\New_IO\tt2.txt”);
    Test3.CopyFile(“F:\Java_project_new\src\New_IO\tt2.txt”,
    “F:\Java_project_new\src\New_IO\tt3.txt”);
    } catch (Exception e) {
    e.printStackTrace();
    }
    }

    /**

    • 缓冲字符输入流
      /
      public static void testBuffereReader(String Reader) throws Exception {
      BufferedReader br = new BufferedReader( new FileReader(Reader));
      char [] c = new char [100];
      int len = 0 ;
      while ((len=br.read©) !=-1){
      System.out.println(new String(c,0,len));
      }
      br.close();
      }
      /
      *
    • 缓冲字符输出流
      */
      public static void testBuffereWriter(String Writer) throws Exception {
      BufferedWriter bw= new BufferedWriter( new FileWriter(Writer));
      String str = “Don’t let your past determine the future”;
      bw.write(str);
      bw.flush();
      bw.close();
      }

    /**

    • 使用缓冲字符流cp文件
      */
      public static void CopyFile (String Reader ,String Writer ) throws Exception {
      BufferedReader br = new BufferedReader( new FileReader(Reader));
      BufferedWriter bw= new BufferedWriter( new FileWriter(Writer));
      char [] c = new char[100];
      int len = 0;
      while ((len= br.read©) !=-1){
      bw.write(c,0,len);
      }
      bw.flush();
      bw.close();
      br.close();
      }
      }
上一篇:Socket类的使用


下一篇:Java字符串导出指定格式文件