3 回答
TA贡献1836条经验 获得超13个赞
使用StreamReader.Readline
const Int32 BufferSize = 128;using (var fileStream = File.OpenRead(fileName)) using (var streamReader = new StreamReader(fileStream, Encoding.UTF8, true, BufferSize)) { String line; while ((line = streamReader.ReadLine()) != null) // Process line }
FileStream
FileOptions.SequentialScan
使用File.Readline
StreamReader
var lines = File.ReadLines(fileName);foreach (var line in lines) // Process line
使用File.ReadAllline
String[]
IEnumerable<String>
var lines = File.ReadAllLines(fileName);for (var i = 0; i < lines.Length; i += 1) { var line = lines[i]; // Process line}
使用String.plit
String.Split
using (var streamReader = File.OpenText(fileName)) { var lines = streamReader.ReadToEnd().Split("\r\n".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); foreach (var line in lines) // Process line}
File.ReadLines
FileShare.ReadWrite
- 3 回答
- 0 关注
- 827 浏览
添加回答
举报