标题: 晚上 复习IO流 写了段代码复制一张图片可下面代码运行结... [打印本页] 作者: Alan 时间: 2013-4-15 01:18 标题: 晚上 复习IO流 写了段代码复制一张图片可下面代码运行结... 本帖最后由 Alan 于 2013-4-17 10:10 编辑
复习IO流 写了段代码复制一张图片,可运行结果复制的图片都是0KB ,就完成了新建,不知道问题出在哪里,求告诉高手浏览下
import java.io.*;
class MyInputStream
{
public static void main(String[] args) throws IOException
{
InputStream is = new FileInputStream("1.jpg");
OutputStream os = new FileOutputStream("2.png");
MyBufferedInputStream aa = new MyBufferedInputStream(is);
BufferedOutputStream bb = new BufferedOutputStream(os);
long start = System.currentTimeMillis();
for(int ly = 0;(ly=aa.myRead())!=-1;)
{
bb.write(ly);
}
long end = System.currentTimeMillis();
System.out.println(end+"-"+start+"="+(end-start));
aa.myClose();
bb.close();
}
}
class MyBufferedInputStream
{
private InputStream in;
private byte[] buf = new byte[1024*4];
int pos = 0,count = 0;
MyBufferedInputStream(InputStream in)
{
this.in = in;
}
//一次读一个字节,从缓冲区(字节数组)获取。
public int myRead()throws IOException
{