大神翻一下

知彼解己 2015-01-17 09:20:28
/**
* 文件上传时使用InputStream类进行接收,在DWR官方例中是使用String类接收简单内容
*
* @param uploadFile
* @return
*/
public String uploadFile(InputStream uploadFile, String filename)
throws Exception {
WebContext webContext = WebContextFactory.get();
String realtivepath = webContext.getContextPath() + "/uploadexcels/";
String saveurl = webContext.getHttpServletRequest().getSession()
.getServletContext().getRealPath("/uploadexcels");
File file = new File(saveurl + "/" + filename);
// if (!file.exists()) {
// file.mkdirs();
// }
int available = uploadFile.available();
byte[] b = new byte[available];
FileOutputStream foutput = new FileOutputStream(file);
uploadFile.read(b);
foutput.write(b);
foutput.flush();
foutput.close();
uploadFile.close();
return realtivepath + filename;
}
...全文
535 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
Golden_Dog 2015-01-17
  • 打赏
  • 举报
回复
uploadFile:指向客户端提交的文件 foutput :指向想存到服务器哪里(saveurl + "/" + filename) b:临时开辟的内存(大小和上传文件相当),用来一次性存储上传文件

13,100

社区成员

发帖
与我相关
我的任务
社区描述
Java J2ME
社区管理员
  • J2ME社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧