C#控制台进行文件读写的简单范例

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

C#控制台进行文件写入:
using System;
using System.IO;
class file1 {
    public static void Main()
    {
       string PATH = null;
       Console.WriteLine("file path: ");//这里输入文本所在目录 例如 d:\text.txt
       PATH = Console.ReadLine();
       StreamWriter sw = new StreamWriter(PATH);
       string str = null;
       while(true){
           str = Console.ReadLine();
           if (str == "end") {
               break;
           }
           sw.WriteLine(str);
       }
       sw.Close();  
       Console.ReadKey();
    }
}
C#控制台进行文件读取
using System;
using System.IO;
class file1 {

    public static void Main() {

        string PATH = null;
        Console.WriteLine("file path: ");//这里输入文本所在目录 例如 d:\text.txt
        PATH = Console.ReadLine();
        StreamReader r = File.OpenText(PATH);
        while(!r.EndOfStream){
            Console.WriteLine(r.ReadLine());
        }
        Console.ReadKey();
    }
}