java 文件大數(shù)據(jù)Excel下載實(shí)例代碼
java 文件大數(shù)據(jù)Excel下載實(shí)例代碼
excel可以用xml表示。故可以以此來(lái)實(shí)現(xiàn)邊寫(xiě)邊下載文件
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)出文件通過(guò)流
*/
@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自己寫(xiě)的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();
}
}
}
感謝閱讀,希望能幫助到大家,謝謝大家對(duì)本站的支持!
相關(guān)文章
java項(xiàng)目jar包與jdk的版本不兼容的問(wèn)題解決
這篇文章主要介紹了java項(xiàng)目jar包與jdk的版本不兼容的問(wèn)題解決,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2019-10-10
java.sql.SQLException:com.mysql.cj.jdbc.Driver報(bào)錯(cuò)問(wèn)題解決
這篇文章主要給大家介紹了關(guān)于java.sql.SQLException:com.mysql.cj.jdbc.Driver報(bào)錯(cuò)問(wèn)題解決的相關(guān)資料,文中通過(guò)圖文介紹的非常詳細(xì),需要的朋友可以參考下2023-08-08
Spring項(xiàng)目里將SQL語(yǔ)句寫(xiě)在.sql文件中的方法
這篇文章主要介紹了Spring項(xiàng)目里如何將SQL語(yǔ)句寫(xiě)在.sql文件中的方法,文中給出了詳細(xì)的介紹和示例代碼,相信對(duì)大家的學(xué)習(xí)或者工作具有一定的參考借鑒價(jià)值,有需要的朋友們下面來(lái)一起看看吧。2017-01-01
Spring Boot+Drools規(guī)則引擎整合詳解
本篇文章主要介紹了Spring Boot+Drools規(guī)則引擎整合,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-09-09
教新手使用java如何對(duì)一個(gè)大的文本文件內(nèi)容進(jìn)行去重
用HashSet對(duì)內(nèi)容去重這個(gè)過(guò)程jvm會(huì)內(nèi)存溢出,只能首先將這個(gè)大文件中的內(nèi)容讀取出來(lái),對(duì)每行String的hashCode取模取正整數(shù),可用取模結(jié)果作為文件名,將相同模數(shù)的行寫(xiě)入同一個(gè)文件,再單獨(dú)對(duì)每個(gè)小文件進(jìn)行去重,最后再合并2021-06-06
MyBatis實(shí)現(xiàn)MySQL批量插入的示例代碼
本文主要介紹了MyBatis實(shí)現(xiàn)MySQL批量插入的示例代碼,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2023-05-05

