C # File Flow rollup

Source: Internet
Author: User

Operation files are common, the project often appear such a requirement: Automatically create a file per month, and insert some data into the file, then we will analyze, whether the file exists, if there is a direct open file flow into the file to insert data, if not present, the process of creating a file and then inserting data When inserting data, the way to use the file stream is to take into account the Chinese garbled problem, the following simple implementation method

        Public Static voidInsertData (stringstr) {            stringFilePath =@"F:\1.txt"; if(!file.exists (FilePath)) {                using(FileStream fs =NewFileStream (FilePath, FileMode.Create, FileAccess.Write)) {StreamWriter SW=NewStreamWriter (Fs,encoding.getencoding ("GB2312")); Sw.                    Write (str); Sw.                    Close (); Fs.                Close (); }            }            //Write data in append mode, and encode format only, default is UTF-8 (Chinese garbled)            using(StreamWriter TSW =NewStreamWriter (FilePath,true, Encoding.GetEncoding ("GB2312")) {tsw. Write (System.Environment.NewLine);//line BreakTSW.                Write (str); Tsw.            Close (); }        }

C # File Flow rollup

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.