字符缓冲输入输出流:BufferedReader BufferedWriter

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

/*
 * 字符缓冲输入输出流:BufferedReader 新增方法 :readLine() 每次读取一行;想要使用,不能发生多态
 * 			   BufferedWriter 新增方法 :newLine() 换行操作
 */
public class Dome09 {
     

	public static void main(String[] args) {
     
		//利用字符流拷贝文本
		copytext("aaasss.txt","111.txt");
	}
	
	//利用字符流拷贝文本
	private static void copytext(String src, String depc) {
     
		File fs = new File(src);
		File ds = new File(depc);
		try (BufferedReader reader = new BufferedReader(new FileReader(fs));
				BufferedWriter writer = new BufferedWriter(new FileWriter(ds))){
     
			String line = null;
			while ((line = reader.readLine()) != null){
     
				writer.append(line);
				writer.newLine();
			}

		} catch (FileNotFoundException e) {
     
			e.printStackTrace();
		} catch (IOException e) {
     
			e.printStackTrace();
		}
		
	}

	
	
}

你可能感兴趣的:(IO流)