ITeye博客

文件下载

CodeToMyLaw · 2012-03-31 14:48 · Web前端 · Markdown


	/**
	 * 评论文档文件下载
	 * @return
	 * @throws Exception
	 */
	public String downloadfile()throws Exception{

		try{
			//存放文件的根:   fileRoot = /DPIv5r1MNP_Review;
			AppInfo appInfo = appInfoService.getAppInfoById(Integer.parseInt(appId));
			String appName = appInfo.getAppName();
			String subName = appInfo.getSubCategory().getSubCategoryName();
			String srvName = appInfo.getSubCategory().getSrvCategory().getSrvCategoryName();	
//			应用所在的路径
			String appPath = fileRoot + "/" + srvName + "/" + subName + "/" + appName ;				
			
			
			String commentPath = "";
			commentPath = appPath + "/Doc/comment/" + userId;
			String tmpName = new String(filename.getBytes("ISO8859-1"),"UTF-8"); 
			
			File file=new File(commentPath+"\\"+tmpName);
			FileInputStream fis=new FileInputStream(file);
			this.getResponse().setContentType("application/force-download");
			this.getResponse().setHeader("content-length", String.valueOf(file.length()));
			this.getResponse().setHeader("Content-disposition", "attachment;filename="+ new String(tmpName.getBytes("gb2312"),"iso8859-1"));//new String(file.getName().getBytes("utf-8"),"gb2312")
			ServletOutputStream os=this.getResponse().getOutputStream();
			int length=0;
			while((length=fis.read())!=-1){
				os.write(length);
			}
			if(fis!= null){
				fis.close();
			}
			if(os!= null){
				os.flush();
				os.close();				
			}			
		}catch(Exception e ){
			
		}
		return null;
	}

评论(0)

暂无评论。

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