亲宝软件园·资讯

展开

c#简单读取文本方法 c#简单读取文本的实例方法

人气:0
想了解c#简单读取文本的实例方法的相关内容吗,在本文为您仔细讲解c#简单读取文本方法的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点: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);
                }
            }
        }
    }
}   

加载全部内容

相关教程
猜你喜欢
用户评论