Programing/UWP

UWP 에서 줄 단위로 파일 쓰기 WriteLinesAsync, AppendLinesAsync

Ezzi 2020. 2. 12. 21:02
반응형

 

 

UWP 에서 Streamwriter writeline 처럼 줄 단위로 파일에 문자열을 쓰는 방법 입니다. 

 

결론 적으로 

 

FileIO.WriteLInesAsync

FileIO.AppendLinesAsync

 

의 사용법입니다. 

 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
    private StorageFolder FolderPath = ApplicationData.Current.LocalCacheFolder;
 
    public async void WriteLine(string str)
    {
        string fileName = "file.txt";
        string filePath = FolderPath.Path + "/" + fileName;
 
        var listofstrings = new List<string> { str, };
        if (File.Exists(filePath) == false)
        {
            StorageFile file = await FolderPath.CreateFileAsync(fileName,
                CreationCollisionOption.OpenIfExists);
            await FileIO.WriteLinesAsync(file, listofstrings, Windows.Storage.Streams.UnicodeEncoding.Utf16BE);
        }
        else
        {
            StorageFile file = await FolderPath.GetFileAsync(fileName);
            await FileIO.AppendLinesAsync(file, listofstrings, Windows.Storage.Streams.UnicodeEncoding.Utf16BE);
        }
    }
cs

 

 

github link

https://github.com/Helloezzi/writeline_uwp

 

Helloezzi/writeline_uwp

Contribute to Helloezzi/writeline_uwp development by creating an account on GitHub.

github.com

 

 

 

 

#파일읽기쓰기 

반응형