我寫下載的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 –
如果你覺得這個答案,因爲解決方案。標記它是正確的。 –