반응형

1. 텍스트 파일을 한번에 한줄씩 읽는 방법.

int counter = 0;  
  
// Read the file and display it line by line.  
foreach (string line in System.IO.File.ReadLines(@"c:\test.txt"))
{  
    System.Console.WriteLine(line);  
    counter++;  
}
  
System.Console.WriteLine("There were {0} lines.", counter);  
// Suspend the screen.  
System.Console.ReadLine();

 File 클래스의 ReadLines 메서드를 사용하여 텍스트 파일 내용을 한번에 한줄씩 문자열로 읽어옵니다. 

foreach문을 통해 각 라인에서 읽어온 데이터를 처리할 수 있습니다. 

 

2. 파일 append 함수

File.AppendAllText([FILE PATH], [DATA] );
//띄어 써야 할 경우 
//[DATA] + "\n"

 

반응형

+ Recent posts