2019独角兽企业重金招聘Python工程师标准>>>
private File imageFile;// 上传文件名称private String imageFileFileName;// 上传文件类型private String imageFileContextType;
InputStream is = new FileInputStream(imageFile);String suffixName = imageFileFileName.substring(imageFileFileName.indexOf(".")).toLowerCase();String image = UUID.randomUUID().toString() + suffixName;String fileFolder = new SimpleDateFormat("yyyyMMdd").format(new Date());String targetPath = ServletActionContext.getServletContext().getRealPath("/upload/goodsImage/" + fileFolder);targetPath = CommonUtil.changePath(targetPath);File myPath = new File(targetPath);if (!myPath.exists()) {myPath.mkdirs();}targetPath = targetPath + "\\" + image;OutputStream os = new FileOutputStream(targetPath);byte buffer[] = new byte[8192];Integer count = 0;while ((count = is.read(buffer)) > 0) {os.write(buffer, 0, count);}os.close();is.close();