ITeye博客

Java上传下载

daoshud1 · 2011-05-07 09:07 · java · 编程语言 · Markdown

利用java Cos下载


               String filepath=getRequest().getRealPath("excelpath");//文件绝对路径
	        String filename=getRequest().getParameter("excel");//获得单个文件名
	        String guessCharset="gbk";
	        String path=filepath+"/"+filename;
		    try { //使用iso8559_1编码方式
		        String isofilename = new String(filename.getBytes(guessCharset),
		                             "ISO-8859-1");
		        getResponse().setContentType("application/octet-stream");
		        getResponse().setHeader("Content-Disposition",
		                            "attachment; filename=" + filename);
		        ServletOutputStream out = null;
		        out = getResponse().getOutputStream();
		        ServletUtils.returnFile(path,out);//下载文件
		    }
		    catch(UnsupportedEncodingException ex) {//iso8559_1编码异常
//		        ex.printStackTrace();
		    }catch(IOException e){//getOutputStream()异常。
//		        e.printStackTrace();
		    }

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。