我写下载的servlet,读取HTML文件,就在文件的传输是添加一些垃圾数据这方面有任何建议写入servletOutputStream
,问题,的BufferedOutputStream写入垃圾数据
是代码我现在用这个
int BUFFER_SIZE = 1024 * 8;
servOut = response.getOutputStream();
bos = new BufferedOutputStream(servOut);
fileObj = new File(file);
fileToDownload = new FileInputStream(fileObj);
bis = new BufferedInputStream(fileToDownload);
response.setContentType("application/text/html");
response.setHeader("ContentDisposition","attachment;filename="+dump+".html");
byte[] barray = new byte[BUFFER_SIZE];
while ((bis.read(barray, 0, BUFFER_SIZE)) != -1) {
bos.write(barray, 0, BUFFER_SIZE);
}
bos.flush();
愚蠢的基本小错误,我做,,日Thnx –
如果你觉得这个答案,因为解决方案。标记它是正确的。 –