Adding a UTF-8 BOM to an outputStream causes the last character to not be printed in java
I have this piece of code that adds a BOM UTF-8 to an outputstream . I need to add the BOM since Excel does not identify the UTF-8 encoding implicitly and hence french characters are shown as weird characters in excel .
try {
response.setCon开发者_StackOverflow社区tentType(getContentType(request, response));
response.setContentLength(downloadData.length);
ServletOutputStream os = response.getOutputStream();
//Specify the BOM (Byte order Mask) for UTF-8 so that Excel can identify the encoding and open it in the correct format
os.write(new byte[] { (byte)0xEF, (byte)0xBB, (byte)0xBF });
os.write(downloadData);
os.flush();
response.flushBuffer();
} catch (IOException e) {
logger.error(e);
}
However , when I output the outputstream to a file , the last character is not printed .
Any ideas why ?
Wouldn't the length have to be increased by 3 to account for the BOM?
精彩评论