Easiest way to read from and write to files

后端 未结 12 1729
[愿得一人]
[愿得一人] 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:24

    private void Form1_Load(object sender, EventArgs e)
        {
            //Write a file
            string text = "The text inside the file.";
            System.IO.File.WriteAllText("file_name.txt", text);
    
            //Read a file
            string read = System.IO.File.ReadAllText("file_name.txt");
            MessageBox.Show(read); //Display text in the file
        }
    

提交回复
热议问题