bearhunterUA
bearhunterUA

Reputation: 259

BOM in Windows and Unix

I write new file with lines and need utf-8 with BOM. In my code I add BOM with the simplest way:

printStream.print('\ufeff');
// print lines

And in Win7 this method work fine, but when I execute my jar in Unix I see "?" at prolog and "utf-8 without bom encoding", how can I fix it? Crossplatform prefered... ANSWER:

char[] c = {0xEF, 0xBB, 0xBF};
        for(int i=0; i<3; i++){
            printStream.write(c[i]);
        }

Upvotes: 0

Views: 1434

Answers (1)

Thomas
Thomas

Reputation: 88707

I'm not sure printStream.print('\ufeff'); is the correct way of writing the utf-8 bom. You could try and write the bytes EF BB BF directly.

Example:

char[] bom = { 0xEF, 0xBB, 0xBF }; 
//or byte[] bom= { (byte) 0xEF, (byte) 0xBB, (byte) 0xBF };
printStream.write( bom ); //directly write the bytes

Upvotes: 2

Related Questions