views:

20

answers:

2

Hi people!

My .NET utility AjGenesis is a code generation tool. The compiled binaries runs without glitches under Ubuntu 10.x, and Mono. But I have a problem: generating a java text file (a normal text file for my tool) it generates Byte Order Mark at the beginning of each file. I'm using System.Text.Encoding.Default: in Windows, all OK, in Ubuntu, the Byte Order Mark are three bytes, indicating UTF8, I guess.

This difference is a problem, when I want to compile the generate .java files using ant, or javac, the BOMs generate errors. Then:

  • What encoding to use in Ubuntu/Mono so the generated files could be processed by javac?
  • I tried javac -encoding UTF8 without success, any clues? My guess: it's not for skip BOMs.
  • I tried System.Text.Encoding.ASCII. But my generated files have non ASCII files (Spanish accented letters). If I change the encoding, the BOMs are added, and javac refuses the files. Any suggestion?

TIA

A: 

Don't use Encoding.Default. Why make your output platform specific? Use UTF-8 - and if you have to use UTF-8 without a BOM, you can do that with:

Encoding utf8 = new UTF8Encoding(false);

To be honest though, I'm surprised javac fails. You say you've tried it "without success" - what was the result?

Jon Skeet
A: 

Try instantiating System.Text.UTF8Encoding and supplying a parameter value that doesn't include BOMs. You may read about this here: http://msdn.microsoft.com/en-us/library/s064f8w2.aspx

Vladimir Volodin