try {
			// minio中的地址
			String fileUrl = "adc49bf6c0ea50ae172560ef7a5d7bce:aaa.xls";
			Response download = remoteFileService.fileDownload(fileUrl.split(":")[0]);
			// 获取文件的 inputStream流
			InputStream is = download.body().asInputStream();
			// 设置下载格式
			response.setContentType("application/vnd.ms-excel;charset=UTF-8");
			String contentDisposition = "attachment;fileName=" + java.net.URLEncoder.encode("filename", "UTF-8");
			response.setHeader("Access-Control-Expose-Headers", "Content-Disposition");
			response.setHeader("Content-Disposition", contentDisposition);
			response.setCharacterEncoding("UTF-8");
			// QdpmsFileServiceImpl.writeFile(TemplateExcelUtils.getOutputStream("testName", response), is);
			// 下载的地址
			String destPath = "C:/Users/yourUserName/Desktop/aaa.xls";
			// 设置文件输出流
			FileOutputStream outStream = null;
			try {
				outStream = new FileOutputStream(destPath);
				byte[] buffer = new byte[1024];
				int bytesRead;
				// 将数据写入到要输出的文件中
				while ((bytesRead = is.read(buffer)) != -1) {
					outStream.write(buffer, 0, bytesRead);
				}
			} finally {
				if (outStream != null) {
					outStream.close();
				}
				if (is != null) {
					is.close();
				}
			}
		} catch (Exception e) {
			log.info(e.getMessage());
			throw new RuntimeException(e.getMessage());
		}
		return null;
Logo

DAMO开发者矩阵,由阿里巴巴达摩院和中国互联网协会联合发起,致力于探讨最前沿的技术趋势与应用成果,搭建高质量的交流与分享平台,推动技术创新与产业应用链接,围绕“人工智能与新型计算”构建开放共享的开发者生态。

更多推荐