Java中字节流复制图片FileInputStream FileOutputStream

来源:互联网 发布:大淘客cms建站教程 编辑:程序博客网 时间:2024/05/16 05:47
package com.jr.ch19;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.FileOutputStream;import java.io.IOException;public class Copy {//复制图片public static void main(String[] args) {// TODO Auto-generated method stubFileInputStream fis=null;FileOutputStream fos=null;try {fis=new FileInputStream("F:/IO/potho/pear.jpg");byte [] b=new byte[fis.available()];fis.read(b);fos=new FileOutputStream("E:/potho3/pear3.jpg");fos.write(b);} catch (FileNotFoundException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}finally{try {if(fis!=null){fis.close();}if(fos!=null){fos.flush();fos.close();}} catch (Exception e2) {// TODO: handle exception}}}}复制不要求在同一个目录下。


阅读全文
0 0