本帖最后由 zhanqq2010 于 2014-6-16 00:58 编辑
我有两个类MyBufferedInputStream类和和CopyMp3类
CopyMp3类:
- import java.io.*;
- class CopyMp3
- {
- public static void main(String[] args) throws IOException
- {
- long start=System.currentTimeMillis();
- //copy_1();
- copy_2();
- long end=System.currentTimeMillis();
- System.out.println((end-start)+"毫秒");
- }
- //BufferedInputStream BufferedOutputStream 拷贝mp3文件
- public static void copy_1() throws IOException
- {
- BufferedInputStream bis = new BufferedInputStream(new FileInputStream("0.mp3"));
- BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("1.mp3"));
- int len=0;
- while((len=bis.read())!=-1)
- {
- bos.write(len);
- }
- bos.close();
- bis.close();
- }
-
-
- //MyBufferedInputStream 拷贝mp3文件
- public static void copy_2() throws IOException
- {
- MyBufferedInputStream bis = new MyBufferedInputStream(new FileInputStream("D:\\myTest\\0.mp3"));
- BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("2.mp3"));
- int len=0;
- while((len=bis.myRead())!=-1)
- {
- bos.write(len);
- }
- bos.close();
- bis.myClose();
- }
- }
复制代码 MyBufferedInputStream 类:
- import java.io.*;
- public class MyBufferedInputStream
- {
- private InputStream in;
- private byte [] bytes = new byte[1024];
- private int pos=0; //数组指针
- private int count=0; //数组中的字节数
-
- MyBufferedInputStream(InputStream in)
- {
- this.in = in;
- }
- //一次读取一个字节,从缓冲区中(字节数组)读取
- public int myRead() throws IOException
- {
- if(count==0)
- {
- count = in.read(bytes);
- if(count<0)
- return -1;
- pos=0;
- byte b = bytes[pos];
- count--;
- pos++;
- return b;
- }
- else
- {
- byte b = bytes[pos];
- count--;
- pos++;
- return b;
- }
- //return 1;
- }
-
- //关闭流
- public void myClose() throws IOException
- {
- in.close();
- }
-
- }
复制代码 编译MyBufferedInputStream 类,通过
编译CopyMp3 类时,在控制台输出如下错误。
d:\myTest>javac CopyMp3.java
CopyMp3.java:32: 错误: 无法访问MyBufferedInputStream
MyBufferedInputStream bis = new MyBufferedInputStream(new FileInputStream("D:\\myTest\\0.mp3"));
^ 错误的类文件: . \MyBufferedInputStream.class
无法访问文件: . \MyBufferedInputStream.class (系统找不到指定的路径。)
请删除该文件或确保该文件位于正确的类路径子目录中。1 个错误d:\myTest>
请大神帮我分析一下哪里出了问题,非常感谢。。。
|
|