Setup
"System.IO" 네임스페이스를 추가해야 함
1
|
using System.IO;
|
Usage
- 파일 읽기
.txt 와 .dat 파일을 읽어서 사용함
- File.ReadAllText : 파일의 모든 내용을 읽음
- File.ReadAllLines : 파일의 내용을 한줄씩 읽음
1
2
3
|
string variable = File.ReadAllText("Path");
string[] variable = File.ReadAllLines("Path");
|
cs |
- 파일 작성
.txt와 .dat 확장자로 파일을 작성하여 저장함
- 덮어쓰기
1
2
3
|
StreamWrite writer = new StreamWriter("Path");
writer.WriteLine(string);
writer.Write(string);
|
- 이어쓰기
1
|
StreamWrite writer = new StreamWriter("Path", true);
|
- 실행되고 있는 프로그램 경로 얻기
12 string path = AppDomain.CurrentDomain.BaseDirectory; // C:\\Program file\\Cs\\string text = File.ReadAllText(path + "notepad.txt");cs
'Csharp' 카테고리의 다른 글
C# - 외부 프로그램과 링크 실행, 종료 (0) | 2019.07.22 |
---|---|
WPF - 다른 파일에서 Window.xaml.cs 코드 접근 (0) | 2019.07.22 |
WPF - Tray icon(트레이 아이콘) 과 메뉴 추가, 관리하기 (0) | 2019.07.15 |
WPF - Image 가장자리 부드럽게 하기 (Antialiasing / 안티에일리어싱) (0) | 2019.07.14 |
WPF - Image 컴포넌트에 Uri 경로 설정 (0) | 2019.07.14 |