-
텍스트 파일을 읽어오는 몇가지 방법 [C#]coding/C# 2021. 4. 22. 13:28
C# 에서 텍스트 파일 읽기
1. File 의 ReadAllText, ReadAllLines 사용
// 파일을 하나의 string으로 읽기 string text = System.IO.File.ReadAllText(@"d:\test.txt");
// 배열에 한라인씩 읽기 string[] lines = System.IO.File.ReadAllLines(@"d:\test.txt");
2. StreamReader Readline메서드 사용
string line; System.IO.StreamReader file = new System.IO.StreamReader(@"d:\test.txt"); while((line = file.ReadLine()) != null) { } file.Close();
'coding > C#' 카테고리의 다른 글
C# Visual Studio 단축키 (4) 2022.08.27