基本操作类似与C语言
// 使用 StreamReader 读写为 string 格式
FileStream fileStream = new FileStream("filePath", FileMode.Open);
StreamReader sr = new StreamReader(fileStream);
string line;
while ((line = sr.ReadLine()) != null)
{
string[] strs = line.Split(',');
string str = string.Format("{0}-{1}-{2}-{3}", strs[0], strs[1], strs[2], strs[3]);
Console.WriteLine(str);
}
// 直接读取 但格式是字节
byte[] byteData = new byte[100];
char[] charData;
fileStream.Seek(0, SeekOrigin.Begin);
fileStream.Read(byteData, 0, 100);
charData = Encoding.UTF8.GetChars(byteData);
string fileTxt = new string(charData);
string[] lines = fileTxt.Split('\n');
foreach (string line in lines) {
Console.WriteLine(line);
}
fileStream.Close();