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

时间:2022-02-16 14:51:52 


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#,读取,文本
0
投稿

猜你喜欢

  • SpringRetry重试框架的具体使用

    2022-09-21 00:37:35
  • java使用IO流对数组排序实例讲解

    2023-09-04 02:24:19
  • Android mvvm之LiveData原理案例详解

    2023-09-29 11:49:26
  • Mybatis-plus自定义SQL注入器查询@TableLogic逻辑删除后的数据详解

    2023-04-09 22:36:45
  • springboot整合websocket最基础入门使用教程详解

    2023-11-30 00:20:24
  • Java类中字段可以不赋予初始值的原因分析

    2023-01-05 15:55:49
  • Java 创建两个线程模拟对话并交替输出实现解析

    2022-01-10 02:37:02
  • c#和javascript函数相互调用示例分享

    2023-10-08 21:33:52
  • java过滤器中Filter的ChainFilter过滤链

    2021-09-29 00:03:42
  • Flutter 日历组件简单实现

    2023-10-21 11:04:35
  • 深入C#中get与set的详解

    2022-05-29 21:04:10
  • C#中Hashtable和Dictionary的区别与用法示例

    2023-10-05 03:22:59
  • 深入解析JVM之内存结构及字符串常量池(推荐)

    2023-01-02 19:48:20
  • Android开发之使用150行代码实现滑动返回效果

    2023-03-20 11:08:50
  • 一篇文章带你入门Java接口

    2023-11-06 02:07:55
  • Android开发之merge结合include优化布局

    2022-07-18 07:22:51
  • Android仿微信选择图片和拍照功能

    2023-08-18 05:22:50
  • 使用java技术抓取网站上彩票双色球信息详解

    2022-01-04 14:47:51
  • 解析C#多线程编程中异步多线程的实现及线程池的使用

    2021-10-23 02:36:23
  • Java代码实现酒店管理系统

    2023-08-13 13:09:23
  • asp之家 软件编程 m.aspxhome.com