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(); } }
Face your past without regret. Handle your present with confidence.Prepare for future without fear. keep the faith and drop the fear.
面对过去无怨无悔,把握现在充满信心,备战未来无所畏惧。保持信念,克服恐惧!一点一滴的积累,一点一滴的沉淀,学技术需要不断的积淀!