IO流--拷贝图片
2015-12-02 07:55
337 查看
/* 需求:复制一个图片。 思路: 1.用字节读取流对象和图片关联。 2.用字节写入流对象创建一个图片文件,用于存储获取到的图片数据。 3.通过循环写,完成数据的存储。 4.关闭资源。 */ import java.io.*; class CopyPicture{ public static void main(String[] args) { FileInputStream fis = null; FileOutputStream fos = null; try{ fis = new FileInputStream("C:\\1.jpg"); fos = new FileOutputStream("C:\\2.jpg"); byte[] buffer = new byte[1024]; int length = 0; while((length = fis.read(buffer)) != -1){ fos.write(buffer,0,length); } }catch (IOException e){ try { throw new IOException("复制文件失败"); } catch (IOException e1) { e1.printStackTrace(); } }finally{ try{ if(fis != null) fis.close(); }catch (IOException e){ System.out.println(e.toString()); } try{ if(fos != null) fos.close(); }catch (IOException e){ System.out.println(e.toString()); } } } }
相关文章推荐
- IO流--字节流的读写操作
- DVWA系列之3 medium级别SQL注入
- DVWA系列之3 medium级别SQL注入
- 装饰者设计模式
- IO流--字符流缓冲区(BufferedReader,BufferedWriter)
- 不同题目之间的差异
- IO流--拷贝文本文件
- Quartz.NET开源作业调度框架系列(二):CronTrigger
- 利用webview加载帧动画
- android CheckBox使用和状态获得
- 品读经典之温伯格
- GoldenGate for win安装配置
- 【cocos2d-x 3D游戏开发】1: 2D基础回顾---触摸事件(2.x)
- Unicode编码完全探究
- 通过命令模式搭建一个UI框架
- 简谈微信公众服务号的客服接口
- hive参数调节
- SparkSqlForTest
- Java代理系列-静态代理
- CSS里的各种水平垂直居中基础写法心得