弹出IE下载框提供下载的方法

本文详细阐述了如何通过Java代码实现文件路径的URL解码、重置响应、设置文件类型和内容描述,最终将指定文件以应用/x-msdownload的形式下载至客户端。同时,文章涉及流媒体服务的基本概念及实现过程,包括文件输入流、输出流的操作以及异常处理机制,旨在为开发者提供高效、稳定的文件下载与流媒体服务解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

String pathend = this.getRequest().getParameter("path");
// path:\\172.16.11.101\cic\CICRecPRO\201203\0901\00\Call_2001287506_2001287509.wav
 try {
			pathend=java.net.URLDecoder.decode(pathend,"UTF-8");
		} catch (UnsupportedEncodingException e1) {
			e1.printStackTrace();
		}
		OutputStream os = null;
		InputStream fis = null;
		byte[] temp = null;
		
		try {
			getResponse().reset();
			getResponse().setContentType("application/x-msdownload");
			getResponse().setHeader("Content-Disposition",
					"attachment;filename=" + pathend);
			File file = new File(pathend);
			if (file.exists() == false){
				return NONE;
			}
			fis = new FileInputStream(file);
			os = this.getResponse().getOutputStream();
			temp = new byte[fis.available()];
			int i = 0;
			while ((i = fis.read(temp)) != -1) {
				os.write(temp, 0, i);
			}
			os.flush();
		} catch (Exception e) {
			e.printStackTrace();
		}finally{
				try {
					if(os != null){
						os.close();
					}
					if(fis != null){
						fis.close();
					}
					if(temp != null){
						temp = null;
					}
				} catch (Exception e) {
					e.printStackTrace();
				}
		}
		return NONE;
	}
	


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值