C # Write txt text (code example ),

Source: Internet
Author: User

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 ();}

''

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.