c#读写txt文件

按行顺序读写txt文件

using System.IO;
using System.Text;
public void Read(string path)
{
    StreamReader sr = new StreamReader(path,Encoding.Default);
    String line;
    while ((line = sr.ReadLine()) != null) 
    {
     Console.WriteLine(line.ToString());
    }
}

按空格解析每行数据

string[] position = Regex.Split(line, "\\s+", RegexOptions.IgnoreCase);

你可能感兴趣的:(c#读写txt文件)