码迷,mamicode.com
首页 > 编程语言 > 详细

上传图片java

时间:2015-06-01 20:57:12      阅读:139      评论:0      收藏:0      [点我收藏+]

标签:null   图片   file   

if (file != null) {
           try {
               InputStream in = new FileInputStream(file);
               Long size=Long.parseLong(in.available()+"");
               String realName = file.getName();
               String img=(realName.substring(realName.lastIndexOf(".")+1,realName.length())).toLowerCase();
               String dir = ServletActionContext.getRequest().getRealPath("/goodsImg");
               if(size<5000000){
                 File uploadFile = new File("C:\\Users\\Administrator\\Desktop\\img", picName+".jpg");
                 OutputStream out = new FileOutputStream(uploadFile);
                 byte[] buffer = new byte[1024 * 1024];
                 int lenght;
                   while ((lenght = in.read(buffer)) > 0) {
                     out.write(buffer, 0, lenght);
                   }
                   in.close();
                   out.close();
                }
           } catch (Exception e) {
                throw new RuntimeException(e);
           }
       }

本文出自 “dslzc” 博客,请务必保留此出处http://dslzc921029.blog.51cto.com/10187165/1657104

上传图片java

标签:null   图片   file   

原文地址:http://dslzc921029.blog.51cto.com/10187165/1657104

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!