SimpleDateFormat format = new SimpleDateFormat("yyyyMMddhhmmss");
String fileName = format.format(new Date());
FileInputStream input = null;
ServletOutputStream outputStream = null;
File file = null;
try {
file = new File(filePath);
input = new FileInputStream(file);
response.setContentType("application/x-download");
response.setHeader("Content-disposition", "attachment; filename="
+ fileName + "_workPlan.xls");
outputStream = response.getOutputStream();
byte[] b = new byte[1024];
int i = 0;
while ((i = input.read(b)) != -1) {
outputStream.write(b, 0, i);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
input.close();
outputStream.flush();
outputStream.close();
// 删除临时文件
if (file.exists() && file.isFile()) {
file.delete();
}
} catch (IOException e) {
e.printStackTrace();
}
}
分享到:
相关推荐
通过这个名为"httpfiledownload"的项目,开发者可以学习到如何在MFC应用中利用WinINet API实现HTTP文件上传和下载。实践中,开发者可能需要根据实际需求调整代码,例如处理大文件、分块传输、进度显示等高级特性。 ...
标题中的"httpfiledownload文件下载.rar"暗示我们关注的是一个MFC应用程序,它利用WinInet API来下载RAR格式和其他类型的文件,如JPG。这个程序可能包含一个用户界面,用户可以在文本框中输入URL,然后点击“启动...
调用方法 DownLoadFile dlf = new DownLoadFile(Class.this); dlf.ShowDownLoadDialog(下载Urls, 保存路径, 文件名s);
download file with ftp
jQuery File Download是一款基于jQuery的插件,主要用于提供ajax下载功能,从而增强用户的文件下载体验。在Web应用中,传统的文件下载方式通常会中断当前页面的交互,用户必须等待文件下载完毕才能继续操作,这在...
【Github file download-crx插件】是一款专为GitHub和Gist设计的浏览器扩展程序,它主要解决了用户在浏览代码库或Gist时无法直接下载文件的问题。通过安装此插件,用户可以方便地在GitHub页面上找到并一键下载所需的...
语言:English (United States) 通过动态365解析撇号包装文件下载问题365....在https://reenhanced.com/2019/how-to-fix-dynamics-365-file-download-apostrophe-bug/上提供更多详细信息由Nick Hance,Software Proj
添加Github的下载按钮和要点 为Github和Gist添加下载按钮 支持语言:English
标题中的"FILE_DOWNLOAD_src_DOWNLOAD-SERVICE.zip_Sharp_auto update"暗示了这是一个关于使用C#语言实现自动更新功能的项目。这个项目可能包含了源代码、文档和其他相关资源,以帮助开发者理解并实现C#中的自动更新...
JoomUnited WP File Download - File Manager WordPress Plugin Joomunited WP文件下载 - 文件管理器WordPress插件" ---------- 泰森云每天更新发布最新WordPress主题、HTML主题、WordPress插件、shopify主题、...
macos下好用的免费下载工具之一
In this paper, we are going to exploit SQL Injection vulnerability in file download function which download file from server on the basis of output returned by vulnerable SQL query.
描述中的 "Windows 7 BT LINK address , download from here" 提示我们这个压缩包包含一个BT链接地址,用户可以通过这个链接在特定的BT客户端上下载Windows 7的Ultimate零售版本。 标签 "Windows 7 BT File" 重申了...
"Secure File Download Class"是一个专为实现安全文件下载而设计的类,它通常用于Web应用程序中,以确保用户能够安全、可靠地获取服务器上的文件资源,同时防止恶意攻击和数据泄露。这个类可能包含了多种安全措施,...
xml file
当我们在编译OpenCV 4.1.0版本时,可能会遇到与FFmpeg相关的错误,如“FFMPEG: Download failed: 6;"Couldn't resolve host name"”。这个错误意味着在下载或更新FFmpeg库的过程中,系统无法解析主机名,...
Six Sigma in Multi stages need to keep track data.
它是一款小巧的 Finder 扩展应用,可以为 Finder 右键菜单中d添加「新建文件」、「拷贝路径」、「打开终端」等功能选项,其中「新建文件」一项可支持许多格式文件的创建操作,比如纯文本、富文本、Word/Excel/PPT、...
File file = new File(filePath); try (InputStream fis = new FileInputStream(file)) { // 设置响应头 setHeaders(response, file.getName()); // 写入输出流 byte[] buffer = new byte[1024]; int ...