import java.io.*;
public class Test4 {
public static void main(String[] args)
{
BufferedOutputStream bo=null;
BufferedInputStream bi=null;
try
{
bi=new BufferedInputStream(new FileInputStream("D:\\123.jpg"));
bo=new BufferedOutputStream(new FileOutputStream("d:\\Demo_copy.jpg"));
byte[] buf=new byte[1024];
int len = 0;
//这里改一下,你原来不停地重复写入读取的第一组数据
while((len = bi.read(buf))!=-1)
{
bo.write(buf, 0,len);
bo.flush();
}
}
catch(IOException e)
{
System.out.println("你的路径是错误的!");
}
finally
{
if(bi!=null)
{
try
{
bi.close();
}
catch(IOException e)
{
System.out.println("读取流关闭失败!");
}
}
if(bo!=null)
{
try
{
bo.close();
}
catch(IOException e)
{
System.out.println("输入流关闭失败!");
}
}
System.out.println("复制成功!");
}
}
}
|