Create a text file and use different codes to generate garbled characters.

Source: Internet
Author: User
There is a program in the past two days. I need to dynamically create several text files.

I usually use
System. Io. streamwriter m_sw;

M_sw = system. Io. file. createtext (m_workfilename );

Create a text document. After the document is created, I add the content in another file.

The result is garbled.

I read the article and summarized the following points:

1. All text files must be encoded,

For example, system. Io. file. createtext is encoded in UTF-8.

2. We can use system. Text. coding. getencoding (INT codeint) to obtain the encoding information.

3. Pass
M_encoding = system. Text. encoding. getencoding (54936 );

M_sw = new streamwriter

(This. m_workfilename, false, m_encoding );

We can create a specified encoded file.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.