`
312350968
  • 浏览: 209249 次
  • 性别: Icon_minigender_1
  • 来自: 济南
社区版块
存档分类
最新评论

上传图片

 
阅读更多

 

	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();
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics