欢迎来到代码驿站!

JAVA代码

当前位置:首页 > 软件编程 > JAVA代码

java 文件大数据Excel下载实例代码

时间:2021-01-20 14:17:06|栏目:JAVA代码|点击:

java 文件大数据Excel下载实例代码

excel可以用xml表示。故可以以此来实现边写边下载文件

package com.tydic.qop.controller; 
 
import java.io.BufferedInputStream; 
import java.io.BufferedOutputStream; 
import java.io.ByteArrayInputStream; 
import java.io.ByteArrayOutputStream; 
import java.io.IOException; 
import java.io.InputStream; 
import javax.servlet.ServletOutputStream; 
import javax.servlet.http.HttpServletResponse; 
import org.springframework.stereotype.Controller; 
import org.springframework.web.bind.annotation.RequestMapping; 
import org.springframework.web.bind.annotation.ResponseBody; 
import com.tydic.qop.vo.param.RealTimeReportParamVo; 
 
@Controller 
@RequestMapping(value = "/exportStream") 
public class testExportByStream { 
  /* 
   * 导出文件通过流 
   */ 
  @RequestMapping(value = "/exportStream.html") 
  @ResponseBody 
   public String exportByStream(RealTimeReportParamVo params, HttpServletResponse response) throws Exception{ 
 
    String fileName="接口统计分析"; 
     
    response.reset(); 
    response.setContentType("application/octet-stream;charset=utf-8"); 
    response.setHeader("Content-Disposition", "attachment;filename="+ new String((fileName + ".txt").getBytes(), "iso-8859-1")); 
    ServletOutputStream out = response.getOutputStream(); 
    BufferedInputStream bis = null; 
    BufferedOutputStream bos = null; 
    for(int i=0;i<1000000;i++){ 
      String contentStr="aaa自己写的controller"+i+"\n"; 
      System.out.println(contentStr); 
      byte[] contentByte=(contentStr).getBytes(); 
      InputStream is = new ByteArrayInputStream(contentByte); 
      readWrite(is,out,bis,bos); 
       
    } 
      if (bis != null) 
        bis.close(); 
      if (bos != null) 
        bos.close(); 
    return null; 
  } 
   
  public void readWrite(InputStream is,ServletOutputStream out,BufferedInputStream bis,BufferedOutputStream bos){ 
    try { 
      bis = new BufferedInputStream(is); 
      bos = new BufferedOutputStream(out); 
      byte[] buff = new byte[2048]; 
      int bytesRead; 
      // Simple read/write loop. 
      while (-1 != (bytesRead = bis.read(buff, 0, buff.length))) { 
        bos.write(buff, 0, bytesRead); 
      } 
      bos.flush(); 
    } catch (final IOException e) { 
      e.printStackTrace(); 
    } 
  } 
} 

感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!

上一篇:如何实现广告弹窗触达频率的控制?

栏    目:JAVA代码

下一篇:详解SpringMVC的url-pattern配置及原理剖析

本文标题:java 文件大数据Excel下载实例代码

本文地址:http://www.codeinn.net/misctech/48160.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有