欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

萬能文件輸出流(超級好用)

程序员文章站 2022-03-11 12:03:05
...
這幾天寫代碼用到了文件輸出,在網上找到這個方法,超級好用,能準確輸出(word,excel,pdf,zip等),記下以後備用,哈哈


int _nread = 0;
byte[] _buffer = new byte[1024];
File tFile = new File(temp.getZipDir() + "\\" + zipFileName);
BufferedInputStream _buffInputStream =
new BufferedInputStream(Resources.getAsInputStream(tFile));
ServletOutputStream _outputStream = resp.getOutputStream();

while( (_nread= _buffInputStream.read(_buffer)) != -1 ) {
_outputStream.write(_buffer, 0, _nread);
_buffer = new byte[1024];
}

_buffInputStream.close();
_outputStream.flush();
_outputStream.close();

相关标签: Excel