A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© wyw 中级黑马   /  2015-4-18 23:44  /  219 人查看  /  0 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

package day19;
import java.io.*;
public class MyBufferedCopyDemo
{

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

        }
       
        public static void BufferedCopy1() throws IOException
        {
                BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("e:\\33.mp3"));
                BufferedInputStream bis = new BufferedInputStream(new FileInputStream("e:\\22.mp3"));
               
                int ch = 0;
               
                while((ch=bis.read())!=-1)
                {
                        bos.write(ch);
                }
               
                bos.close();
                bis.close();
        }

}

class MyBufferedInputStream
{
        private InputStream in;
        private byte [] buf = new byte [1024];
        private int pos = 0,count = 0;
        MyBufferedInputStream(InputStream in)
        {
                this.in =in;
        }
        //一次读一个字节,从缓冲区(字节数组)获取
        public int myRead() throws IOException
        {
                //通过in对象读取硬盘上数据,并存入buf中
                if(count == 0)
                {
                count = in.read(buf);
                byte b =buf[pos];
                count--;
                pos++;
                return b;
                }
                else if(count>0)
                {
                        byte b =buf[pos];
                        count--;
                        pos++;
                        return b;
                }
                return -1;       
        }
        public void myClose()throws IOException
        {
                in.close();
        }
}


0 个回复

您需要登录后才可以回帖 登录 | 加入黑马