using System;
using System.IO;
namespace Example
{
class OprateFile
{
public OprateFile()
{
total = "";
temp = "";
}
public void readInf()
{
while (temp != "bye")
{
temp = Console.ReadLine();
total += temp + "\r\n";
}
}
public void WriteInf()
{
using (StreamWriter sw = new StreamWriter("C:\\Text.txt", false))
{
sw.Write(total);
}
}
private string total;
private string temp;
}
class TestDelegates
{
static void Main()
{
OprateFile of = new OprateFile();
of.readInf();
of.WriteInf();
}
}
}
string total;
string temp="";
while(temp!="bye")
{
temp=Console.Readline();
total+=temp;
}
写入文件则引入IO空间
用FileStream或StreamWriter去写,具体的使用根据具体情况了