//判斷文字檔案行數方法 /// <summary>
/// 獲取文字檔案的行數
/// </summary>
/// <param name="path">文字檔案的路徑</param>
/// <returns>行數</returns>
public int lineIndex(string path)
{
int Length = 0;
StreamReader FileStreamTemp = new StreamReader(path);
while ((FileStreamTemp.ReadLine()) != null)
Length++;
}
FileStreamTemp.Close();
return Length;
} //逐行讀取方法 private void ReadTXTLineByLine()
string path = "";
System.IO.StreamReader file = new System.IO.StreamReader(path);//建立檔案流,path為文字檔案路徑
int counter = 0;
string line = "";
string output = "";
int lineLength = lineIndex(path);
for (int _i = 0; _i < lineLength; _i++)
if ((line = file.ReadLine()) != null)
output = line;
MessageBox.Show("第" + counter.ToString() + "行讀取成功,內容:\n" + output);
} if (_i == (lineLength - 1))
MessageBox.Show("文字已讀取完畢");
//判斷文字檔案行數方法 /// <summary>
/// 獲取文字檔案的行數
/// </summary>
/// <param name="path">文字檔案的路徑</param>
/// <returns>行數</returns>
public int lineIndex(string path)
{
int Length = 0;
StreamReader FileStreamTemp = new StreamReader(path);
while ((FileStreamTemp.ReadLine()) != null)
{
Length++;
}
FileStreamTemp.Close();
return Length;
} //逐行讀取方法 private void ReadTXTLineByLine()
{
string path = "";
System.IO.StreamReader file = new System.IO.StreamReader(path);//建立檔案流,path為文字檔案路徑
int counter = 0;
string line = "";
string output = "";
int lineLength = lineIndex(path);
for (int _i = 0; _i < lineLength; _i++)
{
if ((line = file.ReadLine()) != null)
{
output = line;
MessageBox.Show("第" + counter.ToString() + "行讀取成功,內容:\n" + output);
} if (_i == (lineLength - 1))
{
MessageBox.Show("文字已讀取完畢");
}
}
}