c#開啟檔案後再一行一行地讀檔案(具體一點兒的程式碼)

  • 作者:由 匿名使用者 發表于 曲藝
  • 2022-10-14

c#開啟檔案後再一行一行地讀檔案(具體一點兒的程式碼)’ �2014.03.06 回答

微軟官方示例

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

intcounter = 0;

stringline;

// Read the file and display it line by line。

System。IO。StreamReader file = newSystem。IO。StreamReader(“c:\\test。txt”);

while((line = file。ReadLine()) != null)

{

Console。WriteLine (line);

counter++;

}

file。Close();

// Suspend the screen。

Console。ReadLine();

Top