目前我的程序只打印文本文件中最後的274行。如何在控制檯上打印整個文本文件(約500行)?如何在控制檯中從文本文件打印更多行?
下面是我的代碼:
using System;
namespace InsertTextFileSample
{
class Program
{
static void Main(string[] args)
{
// Example #2
// Read each line of the file into a string array. Each element
// of the array is one line of the file.
string TextFile = Console.ReadLine();
string[] lines = System.IO.File.ReadAllLines(@"C:\Users\Firzanah\Downloads\"+TextFile);
// Display the file contents by using a foreach loop.
System.Console.WriteLine("Contents of nvram.txt = /n");
foreach (string line in lines)
{
// Use a tab to indent each line of the file.
Console.WriteLine("\t" + line);
}
// Keep the console window open in debug mode.
Console.WriteLine("Press any key to exit.");
System.Console.ReadKey();
}
}
}
[編輯]:實測值的溶液這裏:More line in console output of VS2010
它打印所有行。你爲什麼認爲它不?因爲您的控制檯的回滾不夠大,無法顯示全部內容? –
我檢查了控制檯和文本文件中顯示的消息的長度差異。那時我注意到控制檯上只顯示了最後的274行。 如何讓我的回滾顯示全部? – Firzanah