tags:

views:

14

answers:

1

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.setContentType(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 ?

+1  A: 

Wouldn't the length have to be increased by 3 to account for the BOM?

Ignacio Vazquez-Abrams
Increase the length ?? of what ?
rush00121
... Of your content.
Ignacio Vazquez-Abrams
Oh ya... thanks , I overlooked that one :)
rush00121