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