使用CreateFileAsync在哪里创建文件?

考试

当我调用以下函数时,它应该创建一个.txt文件并在其中写一个句子。它似乎执行没有任何错误。但是创建后找不到该文件的存储/位置。我运行Windows搜索来查找文件,但没有任何反应。该文件在哪里?另外,放置该程序使用的.txt文件的最佳文件夹/位置是什么?我应该将其放在Visual Studio的“解决方案资源管理器”中还是“ Debug”文件夹中?

    private async void CreateFile() {
     try {
      // Create sample file, replace if exists.
      StorageFolder storageFolder = ApplicationData.Current.LocalFolder;
      StorageFile sampleFile = await storageFolder.CreateFileAsync("sample.txt", CreationCollisionOption.ReplaceExisting);

      sampleFile = await storageFolder.GetFileAsync("sample.txt");

      await FileIO.WriteTextAsync(sampleFile, "Swift as a shadow!");
     } catch (Exception ex) {
      textBox.Text = ex.ToString();
     }
    }
妮贝瑞

您可以让代码显示路径:

sampleFile = await storageFolder.GetFileAsync("sample.txt");
await new MessageDialog(sampleFile.Path).ShowAsync();

在Windows 10上,这将是如下路径:

C:\Users\[username]\AppData\Local\Packages\[Package family name]\LocalState\sample.txt

其中username是已登录用户的名称,软件包家族名称是您应用程序的软件包家族名称

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章