java基础知识回顾之javaIO类---BufferedInputStream和BufferedOutputStream

MP3的复制过程:

package com.lp.ecjtu;



import java.io.BufferedInputStream;

import java.io.BufferedOutputStream;

import java.io.FileInputStream;

import java.io.FileNotFoundException;

import java.io.FileOutputStream;

import java.io.IOException;





/**

 * 

 * @author Administrator

 * 演示MP3的复制

 * BufferedOutputStream

 * BufferedInputStream

 *

 */

public class CopyMp3Stream {



    /**

     * @param args

     * @throws IOException 

     */

    public static void main(String[] args) throws IOException {

        long startTime = System.currentTimeMillis(); 

        copy_1();

        long endTime = System.currentTimeMillis();

        System.out.println("共耗费"+(endTime-startTime)+"毫秒");

    }

    

    public static void copy_1() throws IOException{

        //创建一个内部缓冲数组,读硬盘中的数据到缓冲区中,字节流缓冲区

        BufferedInputStream bufIos = new BufferedInputStream(new FileInputStream("D:\\1.mp3"));

        BufferedOutputStream buffos = new BufferedOutputStream(new FileOutputStream("2.mp3"));

        int by = 0;

        

        while((by=bufIos.read()) != -1){//读取缓冲区的数据到输入流中

            buffos.write(by);//对输出流进行写操作

        }

        buffos.close();

        bufIos.close();

    }

}

 

你可能感兴趣的:(java基础知识回顾之javaIO类---BufferedInputStream和BufferedOutputStream)