您好,登錄后才能下訂單哦!
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(); } } }
感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。