java033缓冲流复制文本文件

package day03;

import java.io.BufferedReader;

import java.io.BufferedWriter;

import java.io.FileReader;

import java.io.FileWriter;

import java.io.IOException;

public class CopyFileDemo {

public static void main(String[] args) throws IOException {

//创建输入缓冲流对象

BufferedReader br = new BufferedReader(new FileReader("c.txt"));

//创建输出缓冲流对象

BufferedWriter bw = new BufferedWriter(new FileWriter("d.txt"));

/*

//读写数据一次一个字符

int ch;

while((ch=br.read())!=-1){

bw.write(ch);

}*/

//读写数据一次一个字符数组

//首先创建一个数组

char[]chs = new char[1024];

int len;

while((len=br.read(chs))!=-1){

bw.write(chs,0,len);

}

//释放资源

br.close();

bw.close();

}

}

你可能感兴趣的:(java033缓冲流复制文本文件)