C# 程式一次讀取檔案的所有行
使用 ReadAllText() 方法一次讀取檔案的所有行。
假設我們有一個檔案 “hello.txt”,其中包含以下行 −
One Two Three
要讀取上述檔案,請將檔案路徑作為引數新增。
File.ReadAllText(myPath);
上面,myPath 包含檔案路徑。
String myPath = "hello.txt";
讓我們看看完整的程式碼 −
示例
using System;
using System.IO;
public class Demo {
public static void Main() {
String myPath = "hello.txt";
String allLines;
allLines = File.ReadAllText(myPath);
Console.WriteLine(allLines);
}
}輸出
以下是輸出 −
One Two Three
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP