上传图片java

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

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。