文件下载

博客主要讲述了使用Java实现将文件下载到客户端的内容,聚焦于信息技术中Java开发在文件传输方面的应用。

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

下载文件到客户端

HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
HttpServletResponse response = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getResponse();
ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
//把文件输入流写入到字节输出流中,然后把该输出流写到repsonse的输出流中来实现下载文件功能
workbook.write(byteOut);
workbook.close();
ServletOutputStream out = response.getOutputStream();
//文件名
String fileName = "activeData.xlsx";
boolean isIeBrowser = request.getHeader("User-Agent").toUpperCase().indexOf("MSIE") > 0;
if (isIeBrowser) {
	fileName = URLEncoder.encode(fileName, "UTF-8");
} else {
	fileName = new String(fileName.getBytes(), "ISO8859-1");
}
//contentType需根据下载文件来设置不同的mime(可百度)
response.setContentType("application/vnd.openxmlformats-officedocument.wordprocessingml.document");
response.setHeader("Content-disposition", "attachment;filename=" + fileName);
out.write(byteOut.toByteArray());
### mmdetection 使用教程 #### 安装配置 为了顺利使用 `mmdetection`,需先完成环境搭建。推荐通过 Anaconda 创建独立 Python 环境并安装依赖项。具体操作如下: 1. 更新 Conda 和 pip 工具至最新版本。 2. 根据操作系统选择合适的 CUDA 版本来安装 PyTorch 及其相关组件[^2]。 ```bash conda install pytorch torchvision torchaudio cudatoolkit=11.3 -c pytorch ``` 接着克隆 `mmdetection-mini` 仓库到本地机器上,并按照说明文档中的指引执行必要的编译命令以确保所有自定义算子能够正常工作[^1]。 ```bash git clone https://gitcode.com/gh_mirrors/mm/mmdetection-mini.git cd mmdetection-mini pip install -r requirements/build.txt pip install -v -e . ``` #### 示例代码 下面给出一段简单的实例化检测器并对单张图片进行推理预测的Python脚本: ```python from mmdet.apis import init_detector, inference_detector import mmcv config_file = 'configs/faster_rcnn/faster_rcnn_r50_fpn_1x_coco.py' checkpoint_file = 'checkpoints/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth' # 初始化模型 model = init_detector(config_file, checkpoint_file, device='cuda:0') img = 'test.jpg' # 或者 img = mmcv.imread(img),这将会读取图像文件 result = inference_detector(model, img) # 显示结果 model.show_result(img, result, out_file="output.png") ``` 这段程序加载了一个预训练好的 Faster R-CNN 模型权重,并利用它对指定路径下的测试图片进行了目标识别处理,最后保存带有标注框的结果图到当前目录下名为 "output.png" 的文件里。 #### 配置文件调整 对于想要深入定制化的开发者来说,在熟悉框架结构的基础上适当编辑配置文件可以实现更灵活的功能扩展。比如可以在 `mmdetection/configs/_base_/models/` 文件夹内找到不同网络架构的基础设定模板;而在实际项目应用时,则通常会新建特定任务场景所需的个性化参数组合方案[^3]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值