来源:<<C# 4.0图解教程>>
示例:
using System;
using System.IO;
namespace CsDev
{
public class c2
{
public static void Main()
{
using (TextWriter tw1 = File.CreateText("tw1.txt"), tw2 = File.CreateText("tw2.txt"))
{
tw1.WriteLine("tw1 test !");
tw2.WriteLine("tw2 test !");
}
using (TextReader tr1 = File.OpenText("tw1.txt"), tr2 = File.OpenText("tw2.txt"))
{
string s;
while (null != (s = tr1.ReadLine()))
Console.WriteLine(s);
while (null != (s = tr2.ReadLine()))
Console.WriteLine(s);
}
Console.ReadKey();
}
}
}