BufferedInputStream/BufferedOutputStream复制文件

public class Test{

public static void main(String[] args) throws IOException{
FileInputStream in = null;
BufferedInputStream bis =null;
FileOutputStream out =null;
BufferedOutputStream bos =null;
try {
in=new FileInputStream("c:/123/666.doc");
bis=new BufferedInputStream(in);

out=new FileOutputStream("c:/123/999.doc");
bos = new BufferedOutputStream(out);
int len =0;
byte[] buffer = new byte[1024];
while((len=bis.read(buffer))!=-1){
bos.write(buffer, 0, len);
// bos.write(buffer);
}
}
catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally{

bos.flush();    //清空缓存写入数据
bos.close();   //一定要关闭流否则文档打开不了
out.close();
bis.close();
in.close();
}

}

posted @ 2016-07-01 14:54  N神3  阅读(642)  评论(0编辑  收藏  举报