zoukankan      html  css  js  c++  java
  • spring mvc 下载

    1、代码:

      response.setContentType("application/msword;charset=GBK");
        try {
          response.setHeader("Content-Disposition", "attachment;fileName=" + new String(fileName.getBytes("GBK"),"iso-8859-1"));
        } catch (UnsupportedEncodingException e1) {
          logger.error("头文件格式转换异常", e1);
        }
      try {
        URL file = new URL(filepath + usepath);
        InputStream inputStream = file.openStream();

        OutputStream os = response.getOutputStream();
        byte[] b = new byte[2048];
        int length;
        while ((length = inputStream.read(b)) > 0) {
          os.write(b, 0, length);
        }

        //关闭。
        os.close();

        inputStream.close();
       } catch (FileNotFoundException e) {
          e.printStackTrace();
         } catch (IOException e) {
          e.printStackTrace();
        }
      return null;
    }

    2、图片

  • 相关阅读:
    Python闭包相关问题
    Python对象引用问题总结
    Django学习记录
    使用Python访问HDFS
    json模块使用总结——Python
    node-redis使用记录
    nodejs学习笔记(2)
    关于mongodb的mapReduce
    nodejs学习笔记
    关于Python的多重排序
  • 原文地址:https://www.cnblogs.com/wangkang0320/p/6710099.html
Copyright © 2011-2022 走看看