• 文件下载


    @RequestMapping( value = "/download.shtml", method = { RequestMethod.GET, RequestMethod.POST } )
    public void downloadFile( HttpServletResponse response )
    {
     File file  = new File( wjlj );
     String fileName = file.getName();
     response.setCharacterEncoding( "utf-8" ); //设置编码格式
     response.setContentType( "multipart/form-data" );         //设置文件ContentType类型,这样设置,会自动判断下载文件类型  
     response.setHeader( "Content-Disposition", "attachment;fileName=" + fileName );     // 2.设置文件头:最后一个参数是设置下载文件名  

    //(这里  可以设置成excel格式 :response.setHeader("Content-Disposition", "attachment;fileName=" + “文件名” + ".xsl");
            //可以设置成.pdf格式 :response.setHeader("Content-Disposition", "attachment;fileName=" + “文件名” + ".pdf");
     InputStream inputStream = null;
     try {
      inputStream = new FileInputStream( file );
      OutputStream os = response.getOutputStream();
      byte[] b = new byte[2048];
      int length;
      while ( (length = inputStream.read( b ) ) > 0 )
      {
       os.write( b, 0, length );
      }
      os.close();
     } catch ( Exception e ) {
      e.printStackTrace();
     } finally {
      if ( inputStream != null )
      {
       try {
        inputStream.close();
       } catch ( IOException e ) {
        e.printStackTrace();
       }
      }
     }
    }

  • 相关阅读:
    numpy通用函数
    机器学习之随机森林
    机器学习之支持向量机
    机器学习之逻辑回归
    机器学习之决策树
    机器学*之K*邻
    机器学习之线性回归
    模型之各个指标
    模型之信息熵
    模型之决策树
  • 原文地址:https://www.cnblogs.com/libo199374/p/8862512.html
Copyright © 2020-2023  润新知