java 文件大數(shù)據(jù)Excel下載實例代碼
更新時間:2017年04月24日 10:54:50 投稿:lqh
這篇文章主要介紹了java 文件大數(shù)據(jù)Excel下載實例代碼的相關(guān)資料,需要的朋友可以參考下
java 文件大數(shù)據(jù)Excel下載實例代碼
excel可以用xml表示。故可以以此來實現(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 {
/*
* 導出文件通過流
*/
@RequestMapping(value = "/exportStream.html")
@ResponseBody
public String exportByStream(RealTimeReportParamVo params, HttpServletResponse response) throws Exception{
String fileName="接口統(tǒng)計分析";
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)文章
java.sql.SQLException:com.mysql.cj.jdbc.Driver報錯問題解決
這篇文章主要給大家介紹了關(guān)于java.sql.SQLException:com.mysql.cj.jdbc.Driver報錯問題解決的相關(guān)資料,文中通過圖文介紹的非常詳細,需要的朋友可以參考下2023-08-08
Spring Boot+Drools規(guī)則引擎整合詳解
本篇文章主要介紹了Spring Boot+Drools規(guī)則引擎整合,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-09-09
教新手使用java如何對一個大的文本文件內(nèi)容進行去重
用HashSet對內(nèi)容去重這個過程jvm會內(nèi)存溢出,只能首先將這個大文件中的內(nèi)容讀取出來,對每行String的hashCode取模取正整數(shù),可用取模結(jié)果作為文件名,將相同模數(shù)的行寫入同一個文件,再單獨對每個小文件進行去重,最后再合并2021-06-06

