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

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

package mybuffer1;
import java.io.*;
public class MyBuffer
{
        private InputStream r;
        private int count=0,pos=0;
        byte[] buf=new byte[1024];
        MyBuffer(InputStream r)
        {
                this.r=r;
        }
        public int MyRead() throws IOException
        {
               

                if(count==0)
                {
                        if(count<0)
                                return -1;               
                        count=r.read(buf);
                        pos=0;
                        byte bt=buf[pos];
                        pos++;
                        count--;
                        return bt&255;
                }
                else if(count>0)
                {
                        byte bt = buf[pos];
                        pos++;
                        count--;
                        return bt & 0xff;
                }
                return -1;
        }
        public void MyClose()throws IOException
        {
                r.close();
        }

}
package mybuffer1;
import java.io.*;
public class MyBufferDemo {

        public static void main(String[] args) throws IOException
        {
                // TODO Auto-generated method stub
                long start=System.currentTimeMillis();
                Copy();
                long end=System.currentTimeMillis();
                System.out.println("time="+(end-start));
               
        }
        public static void Copy() throws IOException
        {
                MyBuffer mf=new MyBuffer(new FileInputStream("e:\\bbb.mp3"));
                BufferedOutputStream fos=new BufferedOutputStream(new FileOutputStream("e:\\bb.mp3"));
                int ch=0;
                while((ch=mf.MyRead())!=-1)
                     fos.write(ch);
                mf.MyClose();
                fos.close();
        }

}

2 个回复

倒序浏览
因为在转换过程中有可能查码表的时候会遇到查不到对应码表的字符,就会造成一些数据丢失
回复 使用道具 举报
小笨笨SHP 发表于 2016-3-12 15:27
因为在转换过程中有可能查码表的时候会遇到查不到对应码表的字符,就会造成一些数据丢失 ...

哦哦,谢谢流
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马