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);
}
}
}
}
}
您可能感兴趣的文章:
- 一种c#读取文本比较简单的方法
- C#调用存储过程的方法,和简单存储过程创建的方法实例。【转载】为入门的朋友引路,大家互相学习。
- 简单的C# dat文件读取方法
- C#中创建与读取QRCode的方法 - [C#实例]
- C#读取XML节点内容方法实例简析
- C#中StreamReader读取中文文本出现乱码的解决方法
- 【转载】C#中StreamReader读取中文文本出现乱码的解决方法
- C#读取文本并入库解决方法
- C#实现xml文件的读取与写入简单实例
- java学习笔记——jsp简单方法读取txt文本数据
- C#使用Mutex简单实现程序单实例运行的方法
- C#中StreamReader读取中文文本出现乱码的解决方法
- C#实现最简单的文本加密方法
- C# TreeView读取数据库简单实例
- C#中StreamReader读取中文文本出现乱码的解决方法
- c#读取excel方法实例分析
- C#中读取XML到Dataset最简单的方法.
- Asp.Net读取服务器EXE文件的方法!(超简单实例)
- C#中StreamReader读取中文文本出现乱码的解决方法
- C#读取txt文本文件(dat)的方法