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();
}
}