本帖最后由 xuehuayous 于 2014-3-25 16:01 编辑
通过自动以缓冲区可以知道缓冲区的大小,那么调用BufferedInputStream、BufferedOutputStream开辟的缓冲区大小是多少呢?- package com.itheima;
- import java.io.BufferedInputStream;
- import java.io.BufferedOutputStream;
- import java.io.FileInputStream;
- import java.io.FileOutputStream;
- import java.io.IOException;
- public class Java19_12 {
- public static void main(String[] args) {
- long start = System.currentTimeMillis();
- copy();
- long end = System.currentTimeMillis();
- System.out.println((end-start)+"毫秒");
- }
- public static void copy() {
- FileInputStream fis = null;
- FileOutputStream fos = null;
- BufferedInputStream bufis = null;
- BufferedOutputStream bufos = null;
- try {
- fis = new FileInputStream("F:\\阿甘正传.rmvb");
- fos = new FileOutputStream("E:\\阿甘正传.rmvb");
- //定义字节流缓冲区
- bufis = new BufferedInputStream(fis);
- bufos = new BufferedOutputStream(fos);
- int by = 0;
- while((by=bufis.read())!=-1) {
- bufos.write(by);
- }
- } catch (IOException e) {
- System.out.println("视频读写失败!");
- } finally {
- try {
- if(fis!=null)
- fis.close();
- } catch (IOException e) {
- System.out.println("视频读取关闭失败!");
- }
- try {
- if(fos!=null)
- fos.close();
- } catch (IOException e) {
- System.out.println("视频写入关闭失败!");
- }
- }
- }
- }
复制代码
|