C# 超简单

来源:百度知道 编辑:UC知道 时间:2024/06/25 12:47:32
我现在想读一个文本文件:
文件名:test.txt
文件内容:
aaaaaa
bbbbbb
cccccc
dddddd
//共4行...

现在我想用ReadLine给他们都读出来,并每一行对应着打出来一个MSG...谢谢了!!!!
就是想一行行打出来~
我印象中,是需要一个FOR循环的啊。。。。

//你印象中的for
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace baidu2
{
class Program
{
static void Main(string[] args)
{
StreamReader s = new StreamReader(@"d:\test.txt");
while (s.EndOfStream ==false )
{
Console.WriteLine(s.ReadLine ());
}

}
}
}

文本读取写入
使用流,方便进一步的操作
#region 文本读取
//以utf8打开
//StreamReader text = new StreamReader(@"c:\regtest.txt");

//指定编码方式
String str;
using (StreamReader strRe = Microsoft.VisualBasic.FileIO.FileSystem.OpenTextFileReader(@"c:\regtest.txt", System.Text.Encoding.Default))
{
str = strRe.ReadToEnd();