C # program: how to write and export content to notepad

Source: Internet
Author: User

In the C # program, some configuration confidence markers are stored outside the program. If the database is used, it will be useless. Therefore, *. TXT ,*. dat and other storage, which is convenient and fast, and can reduce the burden on the program

The following describes how to write and export content to and from notepad in the C # program.

 

The following code example shows how to use the writealltext method to write content to a file. In this example, if the file does not exist, create a file and add content to it.

 

Using system; using system. IO; using system. text;

Class test {public static void main () {string Path = @ "C: \ temp \ mytest.txt"; // path of the content file to be written, which is also the path of the exported Content File

 

// This method can only add text to the file once, and overwrite the original text if (! File. exists (PATH) {// if the target text does not exist, create a new file string createtext = "Hello and welcome" + environment. newline; // text content, followed by a line feed command file. writealltext (path, createtext, encoding. utf8); // write content}

// If the target text exists, use the following method to add the text, which does not overwrite the original content and only append the text.

String appendtext = "This is extra text" + environment. newline; file. appendalltext (path, appendtext, encoding. utf8); // write content

// Export the content according to the path. String readtext = file. readalltext (path, encoding. utf8); // export the content and accept console. writeline (readtext );}}

 

C # program: how to write and export content to notepad

Related Article

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.