package Student;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
public class BufferDemo {
public static void main(String[] args) {
BufferedReader br = null;
BufferedWriter bw = null;
try{
//封装数据源和目的地
br = new BufferedReader(new FileReader("a.txt"));
bw = new BufferedWriter(new FileWriter("copy.txt"));
//一次一个字符
// int ch = 0;
// while ((ch=br.read())!=-1){
// bw.write(ch);
// }
//一次一個字符數組
char[] chs = new char[1024];
int len =0;
while((len=br.read(chs))!=-1){
bw.write(chs, 0, len);
}
}catch (IOException e) {
e.printStackTrace();
}finally{
try {
bw.close();
} catch (IOException e) {
e.printStackTrace();
}
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
|
|