文件上传之文件读写
来源:互联网 发布:外文期刊数据库检索 编辑:程序博客网 时间:2024/06/05 07:08
实例(controller):
@RequestMapping("/NoaddEmp") public String NOaddEmp(@RequestParam("file") CommonsMultipartFile file, Employe employe,HttpServletRequest request) { Long begin = System.currentTimeMillis(); //getRealPath("/img/photo/") .../img/photo 对你没看错 不是.../img/photo/ String fileUrl = request.getRealPath("/img/photo/") +File.separator+file.getOriginalFilename(); FileOutputStream os=null; InputStream is =null;try { os = new FileOutputStream(fileUrl); //is = new FileInputStream(file); is = file.getInputStream(); /* byte[] buffer =new byte[1024]; int len =0; while((len=is.read(buffer))!=-1){ //读取写入文件 方法1 os.write(buffer,0,len); } */ int len=0; while((len=is.read())!=-1){ //读取写入文件 方法2 os.write(len); } os.flush(); is.close(); os.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } Long end = System.currentTimeMillis(); System.out.println("耗时"+(end-begin)+"ms"); employe.setPhoto("/img/photo/"+file.getOriginalFilename()); boolean bl = empService.save(employe); return"redirect:/emp/toList"; }
0 0
- 文件上传之文件读写
- ajax上传文件和csv文件读写
- 读写文件之日志文件
- 读写文件之日志文件
- 读写文件之日志文件
- 读写文件之日志文件
- Unity3D之文件读写文件
- C#之文件读写
- python之读写文件
- qt 之读写文件
- iOS之文件读写
- Android之文件读写
- Unity3D之文件读写
- 数据处理之文件读写
- 数据处理之文件读写
- Qt之读写文件
- Python之文件读写
- Python之文件读写
- 我们的爱行不行呀 不行就算啦
- Java数据类型和常用运算
- ngix
- tools:context=".MainActivity的作用
- Ubuntu 12.04 LTS 中文输入法的安装
- 文件上传之文件读写
- 总结 XSS 与 CSRF 两种跨站攻击
- 时间在界面显示的有时分秒,去掉时分秒的解决方法
- php 求解多项式
- js特效之腾讯视频的图片轮播
- iOS UIAppearance使用详解
- My MFC Study Notes
- java编译
- 各种大型网站技术架构