How do I stop a JSP based download adding a newline to the first character of a file?

drit .

Wow! Another binary file download technique using jsp.
I did some experiment and I found that this one always work for me (under my environment). You may like to experiment a bit.

response.setDateHeader("Expires", 0);
response.setHeader("Pragma", "noCache");
if (request.getProtocol().equals("HTTP/1.1"))
	response.setHeader("Cache-Control", "no-cache");
out.clearBuffer(); // 1st difference, this may solve your problem
response.setHeader("Content-Disposition", "attachment;filename=""+filename+""");
response.setHeader("Content-Type", "application/octet-stream"); // 2nd difference
response.setContentLength (fileLength); // 3rd difference
// ... the rest nearly the same as yours but I am using 
// ... application.getResource()
The 4th difference, is that you allocate lastBuffer to cater for the last buffer. You don't have to do that:- you can use
1) the length returned from read()
2) the write (byte[], offset, length) form
My 2 cents worth :-)