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();
                    }
                }
            }
  • 相关阅读:
    hud 1397
    hdu 1211
    hdu 1124
    hdu 1104
    1788
    hdu 1796
    sdut 2169
    hdu 1019
    $http post 取不到数据
    sql
  • 原文地址:https://www.cnblogs.com/superxuezhazha/p/12340786.html
Copyright © 2011-2022 走看看