package com.a.io;
import java.io.*;
public class CopyPic {
public static void main(String[] args) {
FileOutputStream fos= null;
FileInputStream fis =null;
try
{
fos=new FileOutputStream("C:\\Users\\Administrator\\Desktop\\eq\\新建文件夹\\6.bmp");
fis=new FileInputStream("C:\\Users\\Administrator\\Desktop\\eq\\新建文件夹\\o.bmp");
int num=fis.available();
byte[] buf=new byte[num];
int len=0;
while((len=fis.read())!=-1)
{
fos.write(buf,0,len);
}
}
catch(IOException e)
{
System.out.println("复制文件失败");
}
finally
{
try
{
if(fis!=null)
fis.close();
}catch(IOException e)
{
System.out.println("关闭读取字节流失败");
}
try
{
if(fos!=null)
fos.close();
}catch(IOException e)
{
System.out.println("关闭写入字节流失败");
}
}
}
}
图片拷贝是拷贝了,但是图片打不开,图片可能损坏.损毁或过大,拷贝的图片内存比实际的内存要大出好多
|