SoFunction
Updated on 2025-03-07

How to read and write files on C# console

This article describes the method of reading and writing files on the C# console. Share it for your reference. The details are as follows:

C# console to write files:

using System;
using ;
class file1 {
  public static void Main()
  {
    string PATH = null;
    ("file path: ");
    //The directory where the text is entered here is, for example, d:\    PATH = ();
    StreamWriter sw = new StreamWriter(PATH);
    string str = null;
    while(true){
      str = ();
      if (str == "end") {
        break;
      }
      (str);
    }
    (); 
    ();
  }
}

C# console for file reading

using System;
using ;
class file1 {
  public static void Main() {
    string PATH = null;
    ("file path: ");
    //The directory where the text is entered here is, for example, d:\    PATH = ();
    StreamReader r = (PATH);
    while(!){
      (());
    }
    ();
  }
}

I hope this article will be helpful to everyone's C# programming.