`
CodeToMyLaw
  • 浏览: 7248 次
  • 性别: Icon_minigender_1
  • 来自: 北京
最近访客 更多访客>>
社区版块
存档分类
最新评论

文件下载

 
阅读更多
	/**
	 * 评论文档文件下载
	 * @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;
	}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics