读取复制图片文件

来源:互联网 发布:apache tomcat 7.0.57 编辑:程序博客网 时间:2024/05/21 10:40
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("写入关闭失败");}}}}

1 0
原创粉丝点击