可以复制,就是打开有问题。求解决- package cn.io.stream;
- import java.io.BufferedOutputStream;
- import java.io.FileInputStream;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.io.InputStream;
- public class CopyMp3Test {
- public static void main(String[] args) throws IOException {
-
- MyBufferedInputStream bis=new MyBufferedInputStream(new FileInputStream("3.mp3"));
- BufferedOutputStream bos=new BufferedOutputStream(new FileOutputStream("5.mp3"));
-
- int by=0;
- while((by=bis.myRead())!=-1){
- bos.write(by);
- }
- bos.close();
- bis.myClose();
-
- }
- }
- class MyBufferedInputStream{
-
- private InputStream in;
- public MyBufferedInputStream(InputStream in){
- this.in=in;
- }
- private int pos=0;
- private int count=0;
- byte[] buf=new byte[1024];
-
- public int myRead() throws IOException{
- if(count==0){
- count=in.read(buf);
- if(count<0)
- return -1;
- pos=0;
- byte b=buf[pos];
- count--;
- pos++;
- return b&255;
- }else if(count>0){
- byte b=buf[count];
- count--;
- pos++;
- return b&255;
- }
- return -1;
- }
- public void myClose() throws IOException{
- in.close();
- }
- }
复制代码 |
-
1.jpg
(35.35 KB, 下载次数: 2)
-
2.jpg
(9.42 KB, 下载次数: 2)
|