zoukankan      html  css  js  c++  java
  • JAVA IO 字节流 FileInputStream FileOutputStream

    摘抄自 b站尚硅谷JAVA视频教程

    与字符流操作基本一致.这里给出使用字节流复制一张图片的代码.

    File file = null;
            File gg = null;
            gg = new File("gg.jpg");
            file = new File("ggCopy.jpg");
            FileOutputStream fo=null;
            FileInputStream fi =null;
            try {
                fo = new FileOutputStream(file);
                fi = new FileInputStream(gg);
    
                byte [] bytes = new byte[5];
                int len =0;
                while ((len=fi.read(bytes))!=-1){
                    fo.write(bytes,0,len);
                    ;
                }
            } catch (IOException e) {
                e.printStackTrace();
            }finally {
                if(fo!=null){
                    try{
                        fo.close();
                    }catch (IOException e){
                        e.printStackTrace();
                    }
                }
                if(fi!=null){
                    try{
                        fi.close();
                    }catch (IOException e){
                        e.printStackTrace();
                    }
                }
            }
  • 相关阅读:
    05
    04
    03
    02
    01
    drf 频率类
    drf 视图家族
    drf 之 群改,单改接口
    drf 序列化
    drf 之模块
  • 原文地址:https://www.cnblogs.com/superxuezhazha/p/12340786.html
Copyright © 2011-2022 走看看