在文件上传时,怎么通过选择文件就把文件保存在服务器的临时目录中?

谁的大王 2012-12-13 02:39:16
在文件上传时,怎么通过选择文件就把文件保存在服务器的临时目录中?
能给我一段代码参考吗?急用
...全文
305 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
zxhcloth 2012-12-13
  • 打赏
  • 举报
回复
这个网上应该很多很多资料,都做烂了。
risun88 2012-12-13
  • 打赏
  • 举报
回复
public String execute() throws Exception { //实现上传 InputStream is = new FileInputStream(file); String root = ServletActionContext.getRequest().getRealPath("/upload"); System.out.println(this.getFileContentType() ); File deskFile = new File(root,this.getFileFileName()); OutputStream os = new FileOutputStream(deskFile); byte [] bytefer = new byte[400]; int length = 0 ; while((length = is.read(bytefer) )>0) { os.write(bytefer,0,length); } os.close(); is.close(); return SUCCESS; }

81,092

社区成员

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

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