源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

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

  • 时间:2021-07-13 14:38 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:c#简单读取文本的实例方法
[u]复制代码[/u] 代码如下:
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);                 }             }         }     } }   
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部