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("写入关闭失败");
			}
		}
	}
}

posted on 2015-11-05 10:23  超宇  阅读(181)  评论(0编辑  收藏  举报