반응형
C #을 사용하여 텍스트 파일의 내용 지우기
C #을 사용하여 텍스트 파일의 내용을 어떻게 지울 수 있습니까?
File.WriteAllText(path, String.Empty);
또는
File.Create(path).Close();
FileMode.Truncate 플래그로 파일을 연 다음 닫습니다.
using (var fs = new FileStream(@"C:\path\to\file", FileMode.Truncate))
{
}
using (FileStream fs = File.Create(path))
{
}
파일을 만들거나 덮어 씁니다.
또 다른 짧은 버전 :
System.IO.File.WriteAllBytes(path, new byte[0]);
항상 스트림 작성기를 사용할 수 있으며 매번 오래된 데이터를 지우고 새 데이터를 추가합니다.
using (StreamWriter sw = new StreamWriter(filePath))
{
getNumberOfControls(frm1,sw);
}
참고 URL : https://stackoverflow.com/questions/2695444/clearing-content-of-text-file-using-c-sharp
반응형
'Program Tip' 카테고리의 다른 글
목록에서 대소 문자 구분을 무시하는 방법 (0) | 2020.11.19 |
---|---|
Android에서 프로그래밍 방식으로 알림 표시 줄에서 알림을 제거하는 방법은 무엇입니까? (0) | 2020.11.19 |
장고에서 관리자 CSS 재정의 (0) | 2020.11.19 |
Pause 모나드 (0) | 2020.11.19 |
Firebase android에서 모든 하위 목록을 얻는 방법 (0) | 2020.11.19 |