java 文件大數(shù)據(jù)Excel下載實(shí)例代碼
更新時(shí)間:2017年04月24日 10:54:50 投稿:lqh
這篇文章主要介紹了java 文件大數(shù)據(jù)Excel下載實(shí)例代碼的相關(guān)資料,需要的朋友可以參考下
java 文件大數(shù)據(jù)Excel下載實(shí)例代碼
excel可以用xml表示。故可以以此來實(shí)現(xiàn)邊寫邊下載文件
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 {
/*
* 導(dǎo)出文件通過流
*/
@RequestMapping(value = "/exportStream.html")
@ResponseBody
public String exportByStream(RealTimeReportParamVo params, HttpServletResponse response) throws Exception{
String fileName="接口統(tǒng)計(jì)分析";
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();
}
}
}
感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!
相關(guān)文章
Nginx+SpringCloud Gateway搭建項(xiàng)目訪問環(huán)境
本文主要介紹了Nginx+SpringCloud Gateway搭建項(xiàng)目訪問環(huán)境,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-08-08
IDEA中Java出現(xiàn)無效的源發(fā)行版錯(cuò)誤的解決辦法
這篇文章主要給大家介紹了關(guān)于IDEA中Java出現(xiàn)無效的源發(fā)行版錯(cuò)誤的解決辦法,IDEA中Java出現(xiàn)?效的源發(fā)?版解決辦法出現(xiàn)該問題的原因是項(xiàng)?Project當(dāng)中的jdk與電腦當(dāng)中的jdk版本不?致造成的,需要的朋友可以參考下2023-10-10
Java實(shí)現(xiàn)把兩個(gè)數(shù)組合并為一個(gè)的方法總結(jié)
這篇文章主要介紹了Java實(shí)現(xiàn)把兩個(gè)數(shù)組合并為一個(gè)的方法,結(jié)合實(shí)例形式總結(jié)分析了java常用的四種數(shù)組合并操作技巧,需要的朋友可以參考下2017-12-12

