黑马程序员技术交流社区
标题:
缓冲字节流复制文件、缓冲字符流复制文件
[打印本页]
作者:
javaeea
时间:
2015-9-29 22:03
标题:
缓冲字节流复制文件、缓冲字符流复制文件
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();
}
}
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2