import java.io.*;
class copypic
{
public static void main(String[] args)
{
FileOutputStream fos = null;
FileInputStream fis = null;
try
{
fos = new FileOutputStream("d:\\1.jpg");
fis = new FileInputStream("d:\\2.jpg");
int len = 0;
byte [] b = new byte[1024];
while((len = fis.read(b))!=-1)
{
fos.write(b,0,len);
}
}
catch (IOException e)
{
throw new RuntimeException("复制文件失败");
}
finally
{
try
{
if(fis!=null)
fis.close();
}
catch (IOException e)
{
throw new RuntimeException("读取关闭失败");
}
try
{
if(fos!=null)
fos.close();
}
catch (IOException e)
{
throw new RuntimeException("写入关闭失败");
}
}
}
}
转载于:https://www.cnblogs.com/chaoyu/p/6436968.html