0
我有一個文本文件,我需要逐行讀取。現在根據我的要求,我必須在讀取文本文件後 lines.for這個我想使用跳過(),但它不工作..Here是我的代碼..如何在C#中跳過指定行數後讀取文本文件
string FileToCopy = "D:\\tickets.txt";
if (System.IO.File.Exists(FileToCopy) == true)
{
var fs = new FileStream(FileToCopy, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
using (var reader = new StreamReader(fs))
{
string line;
string rawcdr="";
while (true)
{
while ((line = reader.ReadLine()).Skip(65) != null)
{
if (line != "")
{
rawcdr = line.ToString();
}
var strings = rawcdr.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
if (strings.Length != 0)
{
}
}
}
}
}
在executig上述code.Text文件從第一行讀取,而我確實需要從66閱讀 line ..我哪裏錯了?
..because'(線= reader.ReadLine())'..計算結果爲一個字符串。您正在跳過65個字符。另外,'while(true)'沒有中斷會鎖定這個.. –
@SimonWhitehead如何實現從文本文件跳過65行? – Adi