C # Write txt text (code example ),
C # Write txt text (code example)
// Required namespace using System. IO; using System. Text; // write txt, method 2. Use Stream to Write public static void txtWrite () {// when there are too many contents to write, you also need to use Stream) // create a file if the file does not exist; If yes, overwrite the file StreamWriter sW1 = new StreamWriter (@ "D: \ flie.txt"); // if the file does not exist, create a file. If the file already exists, an exception is thrown. // FileStream fS = new FileStream (@ "D: \ flie.txt", FileMode. createNew, FileAccess. write, FileShare. read); // StreamWriter sW3 = new StreamWriter (fS); // write the character sW1.Write ("asd") to the file; // write a character array char [] charArray = new Char [3] {'1', '2', '3'}; sW1.Write (charArray); // write a part of a character array (10 ~ 15) sW1.Write (charArray, 0, 2); // close the stream sW1.Close ();}
''