package com.heima.gaoshuai;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
public class Test8 {
/**
* 缓冲字节流复制文件、缓冲字符流复制文件
*
* @throws IOException
*/
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new FileReader("zzz.txt"));
BufferedWriter bw = new BufferedWriter(new FileWriter("aaa.txt"));
String line;
while ((line = br.readLine()) != null) {
bw.write(line);
}
br.close();
bw.close();
BufferedInputStream bis = new BufferedInputStream(new FileInputStream("a.txt"));
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("b.txt"));
int len;
byte[] bytes = new byte[1024];
while((len=bis.read(bytes))!=-1){
bos.write(bytes);
}
bis.close();
bos.close();
}
}
|
|