上传图片

来源:互联网 发布:淘宝上架宝贝没有品牌 编辑:程序博客网 时间:2024/06/07 00:38
  FileInputStream fis = null;
         FileOutputStreamfos = null;
         try{
             fis=new FileInputStream(headPhoto);
             fos=new FileOutputStream(newFile(forder,"图片名.png"));
             byte[]buffer = new byte[4096];
             intlength = 0;
             while(  (length=fis.read(buffer))>0   ){
                 fos.write(buffer, 0, length);
             }
         }catch(Exceptione){
             e.printStackTrace();
         }finally{
             if(fis!=null){
                 try{
                      fis.close();
                 }catch(Exceptione){}
             }
             if(fos!=null){
                 try{
                      fos.close();
                 }catch(Exceptione){}
             }
         }