File.CreateText

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello all,

I'm creating a file with the extension mai and the file contents are in
Japanese (シャーã®ã‚¨ã‚¢æŠœã). Now the code works and creates the file, but when I open
it in Wordpad, the japanese text has become シャーã®エア抜ãÂÂ.

Why is this and can anyone help?

Thanks,

Jon
 
Thus wrote Jon,
Hello all,

I'm creating a file with the extension mai and the file contents are
in Japanese (シャーã®ã‚¨ã‚¢æŠœã). Now the code works and creates the file, but
when I open it in Wordpad, the japanese text has become
シャーã®エア抜ãÂÂ.

Why is this and can anyone help?

It seems WordPad only recognizes UTF-8 encoded text when the file includes
a byte order mark (BOM). File.CreateText() creates UTF-8 encoded files without
a BOM.

Therefore, instead of
StreamWriter writer = File.CreateText("file.txt");
use
StreamWriter writer = new StreamWriter("file.txt", false, Encoding.UTF8);
to create your StreamWriter.

Cheers,
 
Back
Top