上传文件相关代码
2013-04-02 07:46
169 查看
/* At this point the application doesn't actually associate the images with a portfolio. This just saves the file to the filesystem */ private void addImage ( File pic, String fileName, String fileSystemHome ) throws IOException { /* add image to the portfolio and save image file to local filesystem */ FileInputStream in = null; FileOutputStream out = null; String directoryName = fileSystemHome; String localPath=getRequest().getSession().getServletContext().getRealPath("/"); File dir = new File ( localPath+directoryName); boolean b=false; if ( !dir.exists() ){ b=dir.mkdirs(); } String targetPath = dir.getPath() + dir.separator + fileName; File picDestination = new File ( targetPath); try { in = new FileInputStream( pic ); out = new FileOutputStream( picDestination ); int c; while ((c = in.read()) != -1) { out.write(c); } }finally { if (in != null) { in.close(); } if (out != null) { out.close(); } } }
if(caseId>0){
fileSystemPath="page/videoManage/pic"; //String picTime=fileSystemPath+"/"+getUploadPicFileName().substring(0,6 ); String picTime=fileSystemPath+"/"+getUploadPicFileName().substring(0,6 )+"/"+String.valueOf(caseId)+"/before"; try { addImage( getUploadPic(), getUploadPicFileName(), picTime ); } catch (IOException e) { this.addFieldError("OpErr", "上传视频截图失败,请查看异常日志"); return "err"; } try{ caseImage.setId(getUploadPicFileName().substring(0, getUploadPicFileName().indexOf("."))); caseImage.setCaseId(caseId); caseImage.setImageUrl(picTime+"/"+getUploadPicFileName()); caseImage.setCaseType(0); caseImage.setImageType(1); Long ong=caseInfoBS.addCaseImage(caseImage); }catch (Exception e) { this.addFieldError("OpErr", "添加视频截图到数据库失败,请查看异常日志"); return "err"; } // try { // this.getResponse().getWriter().write("案件保存成功"); // } catch (IOException e) { // e.printStackTrace(); // } ActionContext.getContext().put("resultBoolean", "1"); }
相关文章推荐
- 大文件上传代码,根据下拉列表框选中的市县镇名保存文件到指定目录下,并将文件相关信息写进数据库
- 文件上传相关代码及解释 java web
- Java多文件上传相关代码
- Android上传文件到服务器的代码
- Spring实现文件上传(示例代码)
- PHP 图片文件上传实现代码
- 文件上传之asp代码,工作原理,以及post包数据格式
- java代码实现文件上传到linux服务器及问题汇总及解决(亲测可行)
- JS实现表单多文件上传样式美化支持选中文件后删除相关项
- Java文件上传下载核心代码
- struts2中实现多个文件同时上传代码
- Jquery AjaxUpload实现文件上传功能代码实例教程
- asp.net 多文件上传,兼容IE6/7/8,提供完整代码下载
- jq 上传文件相关-判断文件名字/大小-弹出文件管理器
- Spring Boot实现文件上传示例代码
- java webservice上传下载文件代码分享
- PHP 文件上传功能实现代码
- 20160113006 asp.net实现ftp上传代码(解决大文件上传问题)
- struts2中实现多个文件同时上传代码
- 自己动手写中文分词解析器完整教程,并对出现的问题进行探讨和解决(附完整c#代码和相关dll文件、txt文件下载)