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

 找回密码
 加入黑马

QQ登录

只需一步,快速开始


  1. import java.io.FileInputStream;
  2. import java.io.FileOutputStream;
  3. import java.io.BufferedOutputStream;
  4. import java.io.IOException;
  5. import java.io.InputStream;
  6. class MyBufferedInputStream
  7. {
  8.         private InputStream in;
  9.         private byte[] buf=new byte[1024];
  10.         private int count=0,pos=0;
  11.         MyBufferedInputStream(InputStream in){
  12.                 this.in=in;
  13.         }
  14.         public  int myRead()throws IOException
  15.         {
  16.                 byte b=0;
  17.                 if(count==0){
  18.                         pos=0;
  19.                         count=in.read(buf);
  20.                         b=buf[pos];
  21.                         count--;
  22.                         pos++;
  23.                         return b&255;
  24.                        
  25.                 }else if(count>0)
  26.                 {
  27.                         b=buf[pos];
  28.                                                
  29.                         count--;
  30.                         pos++;
  31.                         return b&0xff;
  32.                 }
  33.                 return -1;
  34.         }
  35.         public  void myClose()throws IOException
  36.         {
  37.                 in.close();
  38.         }
  39. }
  40. class CopyMusic
  41. {
  42.         public static void main(String[] args)throws IOException
  43.        
  44.         {
  45.                 MyBufferedInputStream mis=new MyBufferedInputStream(new FileInputStream("D:\\我想念你.mp3"));
  46.                 BufferedOutputStream bos=new BufferedOutputStream(new FileOutputStream("D:\\CopyTestMusic.mp3"));
  47.                 int len=0;
  48.                 while((len=mis.myRead())!=-1){
  49.                         bos.write(len);
  50.                 }
  51.                 mis.myClose();
  52.                 bos.close();
  53.         }
  54.        
  55. }
复制代码


0 个回复

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