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);
}
}
}
}
}
相關(guān)文章
C# 中使用Stopwatch計時器實現(xiàn)暫停計時繼續(xù)計時功能
這篇文章主要介紹了C# 中使用Stopwatch計時器可暫停計時繼續(xù)計時,主要介紹stopwatch的實例代碼詳解,代碼簡單易懂,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2022-03-03C#數(shù)據(jù)綁定(DataBinding)簡單實現(xiàn)方法
這篇文章主要介紹了C#數(shù)據(jù)綁定(DataBinding)簡單實現(xiàn)方法,以簡單實例形式簡單分析了C#實現(xiàn)數(shù)據(jù)綁定與讀取的方法,具有一定參考借鑒價值,需要的朋友可以參考下2015-08-08C#使用SQL DataAdapter數(shù)據(jù)適配代碼實例
今天小編就為大家分享一篇關(guān)于C#使用SQL DataAdapter數(shù)據(jù)適配代碼實例,小編覺得內(nèi)容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧2018-10-10C#基于Twain協(xié)議調(diào)用掃描儀,設(shè)置多圖像輸出模式(Multi image output)
這篇文章主要介紹了C#基于Twain協(xié)議調(diào)用掃描儀,設(shè)置多圖像輸出模式(Multi image output)的方法,幫助大家更好的理解和使用c#,感興趣的朋友可以了解下2021-01-01