Easiest way to read from and write to files

后端 未结 12 1899
[愿得一人]
[愿得一人] 2020-11-22 08:04

There are a lot of different ways to read and write files (text files, not binary) in C#.

I just need something that is easy and uses the least amount of c

12条回答
  •  庸人自扰
    2020-11-22 08:37

    The easiest way to read from a file and write to a file:

    //Read from a file
    string something = File.ReadAllText("C:\\Rfile.txt");
    
    //Write to a file
    using (StreamWriter writer = new StreamWriter("Wfile.txt"))
    {
        writer.WriteLine(something);
    }
    

提交回复
热议问题