FileInputStream和FileOutputStream实现照片的复制(二)

来源:互联网 发布:怎么申请淘宝 编辑:程序博客网 时间:2024/05/24 05:58
package cn.io;//FileInputStream和FileOutputStream实现照片的复制(二)//缺点:速度很慢import java.io.*;public class Test7{public static void main(String[] args) {FileInputStream fis=null;FileOutputStream fos=null;try {fis=new FileInputStream("F:\\1.JPG");fos=new FileOutputStream("F:\\2.JPG");int oneByte=0;while((oneByte=fis.read())!=-1){//每次读取一个字节fos.write(oneByte);fos.flush();}} catch (Exception e) {e.toString();}finally{if(fos!=null){try {fos.close();} catch (IOException e) {e.toString();}}if(fis!=null){try {fis.close();} catch (IOException e) {e.toString();}}}}}

原创粉丝点击