- import java.io.FileInputStream;
- import java.io.FileOutputStream;
- import java.io.BufferedOutputStream;
- import java.io.IOException;
- import java.io.InputStream;
- class MyBufferedInputStream
- {
- private InputStream in;
- private byte[] buf=new byte[1024];
- private int count=0,pos=0;
- MyBufferedInputStream(InputStream in){
- this.in=in;
- }
- public int myRead()throws IOException
- {
- byte b=0;
- if(count==0){
- pos=0;
- count=in.read(buf);
- b=buf[pos];
- count--;
- pos++;
- return b&255;
-
- }else if(count>0)
- {
- b=buf[pos];
-
- count--;
- pos++;
- return b&0xff;
- }
- return -1;
- }
- public void myClose()throws IOException
- {
- in.close();
- }
- }
- class CopyMusic
- {
- public static void main(String[] args)throws IOException
-
- {
- MyBufferedInputStream mis=new MyBufferedInputStream(new FileInputStream("D:\\我想念你.mp3"));
- BufferedOutputStream bos=new BufferedOutputStream(new FileOutputStream("D:\\CopyTestMusic.mp3"));
- int len=0;
- while((len=mis.myRead())!=-1){
- bos.write(len);
- }
- mis.myClose();
- bos.close();
- }
-
- }
复制代码
|
|