`
zp19827
  • 浏览: 14856 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

file download

    博客分类:
  • Code
 
阅读更多
 

        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下载与上传文件.rar

    通过这个名为"httpfiledownload"的项目,开发者可以学习到如何在MFC应用中利用WinINet API实现HTTP文件上传和下载。实践中,开发者可能需要根据实际需求调整代码,例如处理大文件、分块传输、进度显示等高级特性。 ...

    httpfiledownload文件下载.rar

    标题中的"httpfiledownload文件下载.rar"暗示我们关注的是一个MFC应用程序,它利用WinInet API来下载RAR格式和其他类型的文件,如JPG。这个程序可能包含一个用户界面,用户可以在文本框中输入URL,然后点击“启动...

    android 下载类(File DownLoad)

    调用方法 DownLoadFile dlf = new DownLoadFile(Class.this); dlf.ShowDownLoadDialog(下载Urls, 保存路径, 文件名s);

    jQueryFileDownload实现ajax下载体验的jQuery插件

    jQuery File Download是一款基于jQuery的插件,主要用于提供ajax下载功能,从而增强用户的文件下载体验。在Web应用中,传统的文件下载方式通常会中断当前页面的交互,用户必须等待文件下载完毕才能继续操作,这在...

    download_file_with_ftp.zip_file download_ftp

    download file with ftp

    Github file download-crx插件

    【Github file download-crx插件】是一款专为GitHub和Gist设计的浏览器扩展程序,它主要解决了用户在浏览代码库或Gist时无法直接下载文件的问题。通过安装此插件,用户可以方便地在GitHub页面上找到并一键下载所需的...

    Dynamics CRM File Download Fix-crx插件

    语言:English (United States) 通过动态365解析撇号包装文件下载问题365....在https://reenhanced.com/2019/how-to-fix-dynamics-365-file-download-apostrophe-bug/上提供更多详细信息由Nick Hance,Software Proj

    Github文件下载「Github file download」-crx插件

    添加Github的下载按钮和要点 为Github和Gist添加下载按钮 支持语言:English

    FILE_DOWNLOAD_src_DOWNLOAD-SERVICE.zip_Sharp_auto update

    标题中的"FILE_DOWNLOAD_src_DOWNLOAD-SERVICE.zip_Sharp_auto update"暗示了这是一个关于使用C#语言实现自动更新功能的项目。这个项目可能包含了源代码、文档和其他相关资源,以帮助开发者理解并实现C#中的自动更新...

    【WordPress插件】2022年最新版完整功能demo+插件v5.4.2 + Addons.zip

    JoomUnited WP File Download - File Manager WordPress Plugin Joomunited WP文件下载 - 文件管理器WordPress插件" ---------- 泰森云每天更新发布最新WordPress主题、HTML主题、WordPress插件、shopify主题、...

    File download manager macos下好用的下载软件之一

    macos下好用的免费下载工具之一

    Local File Disclosure using SQL Injection

    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 File

    描述中的 "Windows 7 BT LINK address , download from here" 提示我们这个压缩包包含一个BT链接地址,用户可以通过这个链接在特定的BT客户端上下载Windows 7的Ultimate零售版本。 标签 "Windows 7 BT File" 重申了...

    Secure-File-Download-Class.zip_class_secare class

    "Secure File Download Class"是一个专为实现安全文件下载而设计的类,它通常用于Web应用程序中,以确保用户能够安全、可靠地获取服务器上的文件资源,同时防止恶意攻击和数据泄露。这个类可能包含了多种安全措施,...

    xml file download

    xml file

    Six Sigma Project File in Excel

    Six Sigma in Multi stages need to keep track data.

    Easy New File_4.5(54).dmg

    它是一款小巧的 Finder 扩展应用,可以为 Finder 右键菜单中d添加「新建文件」、「拷贝路径」、「打开终端」等功能选项,其中「新建文件」一项可支持许多格式文件的创建操作,比如纯文本、富文本、Word/Excel/PPT、...

    java web download file

    File file = new File(filePath); try (InputStream fis = new FileInputStream(file)) { // 设置响应头 setHeaders(response, file.getName()); // 写入输出流 byte[] buffer = new byte[1024]; int ...

    解决opencv3.2 OpenCVUtils.cmake:1047错误

    /cmake/.download/151805e03568c9f490a5e3a872777b75/vgg_generated_120.i] expected hash: [151805e03568c9f490a5e3a872777b75] actual hash: [d41d8cd98f00b204e9800998ecf8427e] status: [7;"Couldn't connect...

Global site tag (gtag.js) - Google Analytics