c#简单读取文本的实例方法
using system;
using system.collections.generic;
using system.linq;
using system.text;
using system.io;
namespace streamreadwrite
{
class program
{
static void main(string[] args)
{
// get the directories currently on the c drive.
directoryinfo[] cdirs = new directoryinfo(@"e:\").getdirectories();
// write each directory name to a file.
using (streamwriter sw = new streamwriter("cdrivedirs.txt"))
{
foreach (directoryinfo dir in cdirs)
{
sw.writeline(dir.name);
}
}
// read and show each line from the file.
string line = "";
using (streamreader sr = new streamreader("cdrivedirs.txt"))
{
while ((line = sr.readline()) != null)
{
console.writeline(line);
}
}
}
}
}