본문 바로가기
.Net

C# 파일 끝에 추가하기

by Dokon Jang 2021. 4. 15.
반응형

텍스트 파일의 끝에 텍스트를 추가하는 방법입니다.

File 클래스에 파일 끝에 텍스트를 추가 할 수 있는 여러 함수가 존재하는데 간단하게 추가해보도록 하겠습니다.

 

[함수]

※ 자세한 내용은 아래의 링크를 참조하세요.

https://docs.microsoft.com/ko-kr/dotnet/api/system.io.file.appendalltext?view=net-5.0

 

File.AppendAllText 메서드 (System.IO)

지정된 문자열을 파일에 추가합니다. 파일이 아직 없으면 만듭니다.Appends the specified string to the file, creating the file if it does not already exist.

docs.microsoft.com

 

 

[코드]

using (StreamWriter sw = File.AppendText(@"D:\test.txt"))
{
	sw.WriteLine("");
	sw.WriteLine("------------------------------------------------------------------------");
	sw.WriteLine("파일 끝에 쓰기 테스트");
	sw.WriteLine("------------------------------------------------------------------------");
}
반응형

댓글