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