使用的是apache common下的fileupload
解决方案 »
- 【分享】MyEclipse8.6优化及部分用法
- 跪求新的JavaEE项目教程或者建议
- HADOOP0.21.0与HBASE0.20.6的冲突
- Wap go标签疑问????? 紧急求助.....高分答谢......
- Tomcat下可以正常运行,移到oc4j下就出错了。帮帮忙,谢谢了
- mybatis 配置问题,咨询
- struts的一个数据问题?
- struts 页面的显示问题
- EJB访问的问题
- CMP一定要用TXDATASOURCE吗?tx datasource和datasource有什么不同?
- encType=multipart/form-data request取不出来值
- 急急急!!! 小弟遇到了一个问题, 配置hibernate时, 愁死啦
FormFile lifePhoto = form.getLifePhoto();
String filePath = httpServletRequest.getSession().getServletContext().getRealPath("/");
if(workPhoto!=null){
try{
InputStream stream = workPhoto.getInputStream(); //把文件读入
/*
* 建立一个上传文件的输出流 如果是linux系统请把UploadFiles后的"\\"换成"/" OutputStream bos = new FileOutputStream(filePath +
"lwuser\\fileUpload\\"+fileName); int bytesRead = 0;
byte[] buffer = new byte[8192];
while ((bytesRead = stream.read(buffer, 0, 8192)) != -1)
{
bos.write(buffer, 0, bytesRead);//将文件写入服务器
}
bos.close();
stream.close();
photoPath[0]="\\lwuser\\fileUpload\\"+fileName; }catch(FileNotFoundException ex){
System.out.println( "文件上传失败: "+ex);
throw new FileNotFoundException(ex.toString());
}catch(IOException ex){
System.out.println( "文件上传失败: "+ex);
throw new FileNotFoundException(ex.toString());
}
}
这里只是片段,仅供参考!