IT노트(구)/C#
(C#) 파일 내용 출력하는 방법, ReadAllLines() 이용
스프링연구소
2015. 12. 2. 17:38
C#에서 ReadAllLines()를 사용하면
파일 내용을 가져올 수 있다!(라인 단위로)
예제 소스는 다음과 같다!(간단해서 직관적으로 이해할 수 있을 것이다!)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 |
using System;
class Test
{
public static void Main()
{
string path = @"C:\WorkSpace\Test.txt"; // 파일 경로
string[] lines = System.IO.File.ReadAllLines(path); // ReadAllLines() 메소드 실행
foreach(string s in lines) // 루프를 돌면서 한 줄씩 출력
{
Console.WriteLine(s);
}
}
} |
cs |