zoukankan      html  css  js  c++  java
  • java 网络文件下载(并命中文名)

    public void download(HttpServletRequest request, HttpServletResponse response){
            //获取服务器文件
            String file_url = "http//:www.baidu.com/201811239413.doc";
    
            InputStream ins = null;
            try {
                ins = new URL(file_url).openStream();
                /* 设置文件ContentType类型,这样设置,会自动判断下载文件类型 */
                response.setContentType("multipart/form-data");
                /* 设置文件头:最后一个参数是设置下载文件名 */
                response.setHeader("Content-Disposition", "attachment;filename*=UTF-8''" + URLEncoder.encode("江苏南京.doc","UTF-8"));//适应中文名称
                OutputStream os = response.getOutputStream();
                byte[] b = new byte[1024];
                int len;
                while((len = ins.read(b)) > 0){
                    os.write(b,0,len);
                }
                os.flush();
                os.close();
                ins.close();
            } catch (FileNotFoundException e) {
                System.out.println("没有该文件");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            } catch (MalformedURLException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
  • 相关阅读:
    mongoDb
    profile ,explain,
    header 里面的contenttype
    group by,distinct的使用(30万数据测试)
    ubuntu 12.04 mysql 错误 Errcode 13
    php curl,爬虫
    explain mysql
    php 文件的函数
    create User,grand,Load data file
    android 按钮点击测试
  • 原文地址:https://www.cnblogs.com/wanyong-wy/p/10059916.html
Copyright © 2011-2022 走看看