File.CreateText

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
 
J

Joerg Jooss

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,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,610
Members
45,254
Latest member
Top Crypto TwitterChannel

Latest Threads

Top