81,092
社区成员
发帖
与我相关
我的任务
分享
<img width="80" hight="200" disabled="true"
src="<bean:write name='bean' property='picture'/>" width="50"
height="50">
FormFile file = newsForm.getFile();
if (file != null && file.getFileSize() > 0) {
String fileName = file.getFileName();
// 文件大小
int fileSize = file.getFileSize();
// 文件流
InputStream is = file.getInputStream();
// 将输入流保存到文件
String rootPath = this.servlet.getServletContext().getRealPath(
"upload");
File f = new File(rootPath);
if (!f.exists())
f.mkdirs(); // 如果文件夹不存在,则创建
String ext = "";
int pos = fileName.lastIndexOf(".");
ext = fileName.substring(pos);// 得到扩展名
Date date=new Date();
String newsFileName = String.valueOf(date.getTime()) + ext;
FileOutputStream fos = null;
try {
fos = new FileOutputStream(new File(f, newsFileName));
byte[] b = new byte[1024];
int real = 0;
real = is.read(b);
while (real > 0) {
fos.write(b, 0, real);
real = is.read(b);
}
} catch (RuntimeException e1) {
e1.printStackTrace();
return mapping.findForward("no");
}
fos.close();
is.close();
file.destroy();
news.setPicture(rootPath+ "\\" + newsFileName);