久久96国产精品久久久-久久发布国产伦子伦精品-久久精品国产精品青草-久久天天躁夜夜躁狠狠85麻豆

技術(shù)員聯(lián)盟提供win764位系統(tǒng)下載,win10,win7,xp,裝機(jī)純凈版,64位旗艦版,綠色軟件,免費(fèi)軟件下載基地!

當(dāng)前位置:主頁 > 教程 > 服務(wù)器類 >

java 文件大數(shù)據(jù)Excel下載實(shí)例代碼教程

來源:技術(shù)員聯(lián)盟┆發(fā)布時間:2017-06-27 00:51┆點(diǎ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)計分析"; 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(); } } }