java基础知识回顾之javaIO类---FileInputStream和FileOutputStream字节流复制图片
package com.lp.ecjtu; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; /** * * @author Administrator * 1.用字节读取流对象和图片相关联(输入流) * 2.用字节写入流对象创建一个图片文件。用于存储获取到的图片数据(输出流) * 3.通过循环读写,完成数据的储存 * 4.关闭资源 * */ public class CopyPicStream { /** * @param args */ public static void main(String[] args) { FileInputStream fis = null; FileOutputStream fos = null; try { fis = new FileInputStream("d:\\1.jpg");//读取图像数据之类的原始字节流 fos = new FileOutputStream("2.bmp");//用于写入诸如图像数据之类的原始字节流 byte[] b = new byte[1024]; int len = 0; while ((len=fis.read(b)) != -1){ fos.write(b); } }catch (FileNotFoundException e) { e.printStackTrace(); }catch (IOException e) { throw new RuntimeException("复制图片失败!"); }finally{ try { if(fis != null){ fis.close(); } } catch (IOException e) { e.printStackTrace(); } try { if(fos != null){ fos.close(); } } catch (IOException e) { e.printStackTrace(); } } } }
Face your past without regret. Handle your present with confidence.Prepare for future without fear. keep the faith and drop the fear.
面对过去无怨无悔,把握现在充满信心,备战未来无所畏惧。保持信念,克服恐惧!一点一滴的积累,一点一滴的沉淀,学技术需要不断的积淀!