大神翻一下
知彼解己 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;
}