使用的是apache common下的fileupload
解决方案 »
- sql语句修改后不执行!!
- 大家喜欢MyEclipse来写JSP吗?
- MyEclipse中如何隐藏导入的包?
- hibernate hql语句怎么实现随机抽取数据库数据
- 引用<ref/>实例问题。
- Spring中配置Proxool连接池数据源--属性问题
- 如何用java实现网络存储,即网络硬盘的功能?
- 一个Java程序面对的选择??
- 请问有用jdk1.4 和 jdbc 连接sqlserver成功的吗.
- 关于动态html表单,struts的actionform应该如何设置?
- 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());
}
}
这里只是片段,仅供参考!