欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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

程序员文章站 2024-02-29 11:43:22
java 文件大数据excel下载实例代码 excel可以用xml表示。故可以以此来实现边写边下载文件 package com.tydic.qop.contro...

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(); 
    } 
  } 
} 

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