Adds a string to the specified file to Appendalltext; Determines if the file for the specified path exists file.exists (path)

Source: Internet
Author: User
Tags readfile

Using system;using system.collections.generic;using system.linq;using system.text;namespace Test{class Program { static void Main (string[] args) {string path = @ "F:\1.txt";//path of the specified file//--------------- -------------------------------            //.             Exists (path) is the determination of whether a file exists under the specified path.            if (System.IO.File.Exists (path)) {Console.WriteLine ("file exists under the specified path");            } else {Console.WriteLine ("The file under the specified path does not exist"); }//----------------------------------------------//The "Nike" string is added to the path of "path" in the Encoding.default encoding way             to the corresponding file. Note: If F:\1.txt this path does not exist 1.txt this file, it will give you automatically generate a 1.txt file, and then to "Nike" This string added to System.IO.File.AppendAllText (path, "Nike", E Ncoding.            Default);            Reads the file under path specified by the Encoding.default encoding method.            String readFile = System.IO.File.ReadAllText (path, encoding.default);            Console.WriteLine (ReadFile); ConsOle.        ReadKey (); }    }}

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.