手机
当前位置:查字典教程网 >编程开发 >C#教程 >c#简单读取文本的实例方法
c#简单读取文本的实例方法
摘要:复制代码代码如下:usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;...

复制代码 代码如下:

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

}

}

}

}

}

【c#简单读取文本的实例方法】相关文章:

用C#对ADO.NET数据库完成简单操作的方法

c#中虚函数的相关使用方法

C#图片压缩的实现方法

c# 托盘双击不触发单击事件的实现方法

C# 一个WCF简单实例

C# WinForm中Panel实现用鼠标操作滚动条的实例方法

c# 获取数据库中所有表名称的方法

C# DataGridView添加新行的2个方法

C#简单的加密类实例

C#最简单的关闭子窗体更新父窗体的实现方法

精品推荐
分类导航