IO编程__缓冲字符流__输入输出

Posted 18513757531

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了IO编程__缓冲字符流__输入输出相关的知识,希望对你有一定的参考价值。

 

 

一、代码如下

package www.tainiu.wenjian;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

public class af__FileHuanZiFuLiu__V1 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		BufferedReader br= null;
		BufferedWriter bw= null;
		
		try {
			FileReader fr= new FileReader("d:\\Test.txt");
			br= new BufferedReader(fr);
			
			FileWriter fw= new FileWriter("e:\\Test__1.txt");
			bw= new BufferedWriter(fw);
			
			String s= "";
			while((s=br.readLine()) != null) {
				//System.out.println(s);
				bw.write(s + "\r\n");
			}
			
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			try {br.close();bw.close();} catch (IOException e) {e.printStackTrace();}
		}
		

	}

}

 

package www.tainiu.wenjian;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

public class af__FileHuanZiFuLiu__V2 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		BufferedReader br= null;
		BufferedWriter bw= null;
		
		try {
			//FileReader fr= new FileReader("d:\\Test.txt");
			br= new BufferedReader(new FileReader("d:\\Test.txt"));
			
			//FileWriter fw= new FileWriter("e:\\Test__1.txt");
			bw= new BufferedWriter(new FileWriter("e:\\Test__2.txt"));
			
			String s= "";
			while((s=br.readLine()) != null) {
				//System.out.println(s);
				bw.write(s + "\r\n");
			}
			
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			try {br.close();bw.close();} catch (IOException e) {e.printStackTrace();}
		}
		

	}

}

 

以上是关于IO编程__缓冲字符流__输入输出的主要内容,如果未能解决你的问题,请参考以下文章

IO流01_字节字符流缓冲流标准输入输出流打印流

IO编程__字符流__输入输出

IO编程__缓冲字符流__应用__记事本的打开保存功能

java _io_字节缓冲流(装饰器)输入输出

IO流07_输入输出流总体系

IO流__字节流 标准输入输出流 转换流