extra new lines with several outputStream.write

Posted by Sam on Stack Overflow See other posts from Stack Overflow or by Sam
Published on 2010-05-09T09:21:04Z Indexed on 2010/05/09 9:28 UTC
Read the original article Hit count: 212

Filed under:

Hi All,

I am writing jsp to export data in excel format to user. An excel could be recieved on the cient side. However, since there's large amount of data, and I don't want to keep it in the server memory and write them at the end. I try to divide them and write serveral times. However, each extra write(..) will cause an extra new lines at the top of the excel worksheet and then the extra data is placed after these new lines. Does anyone know the reasons?

The code is something like this:

response.setHeader("Content-disposition","attachment;filename=DocuShareSearch.xls");
response.setHeader("Content-Type", "application/octet-stream"); 

responseContent ="<table><tr><td>12131</td></tr>.......";
byte[] responseByte1 = responseContent.getBytes("utf-16");
outputStream.write(responseByte1, 0, responseByte1.length ); 

responseContent =".....<tr><td>12131</td></tr></table>";
byte[] responseByte2 = responseContent.getBytes("utf-16");
outputStream.write(responseByte2, 0, responseByte2.length ); 

outputStream.close();

© Stack Overflow or respective owner

Related posts about jsp-tags