1

使用此代碼:Roamingfolder.CreateFileAsync我怎麼關閉文件

private async void writeToStorage(string contents) 
    { 
     var roamingFolder = Windows.Storage.ApplicationData.Current.RoamingFolder; 
     var storFile = await roamingFolder.CreateFileAsync("test", CreationCollisionOption.ReplaceExisting); 

     await Windows.Storage.FileIO.WriteTextAsync(storFile, contents); 
    } 

我是否需要關閉該文件?如果是這樣的話,我該怎麼做? storFile上沒有關閉。

回答

3

不,你不需要關閉這個文件。

StorageFolderStorageFile實例只是指向文件夾和文件的指針。 使用WriteTextAsync方法將自動打開/寫入並關閉流。