2017-08-14 259 views
-1

我已经构建了一个应用程序,用于读取配置文件并加载基于xml的字典。 我想要的是不需要将该文件添加到程序中。相反,我希望能够上传到pi3,然后告诉程序刷新并阅读我上传的文件。它将包含在代码中的文件加载到一个模糊的文件夹中。
如何将我的代码中的路径上载并指定到更容易找到的文件夹中。如何在运行Windows 10的树莓派上上传和读取文件IoT

在此先感谢

+0

我们有一个专门的树莓派堆栈交换 - 试试发布您的问题那里https://raspberrypi.stackexchange.com/ –

+0

谢谢。我将这样做 –

+0

您可以检查[文件访问权限](https://docs.microsoft.com/en-us/windows/uwp/files/file-access-permissions)和[读取文件](https:/ /docs.microsoft.com/en-us/windows/uwp/files/quickstart-reading-and-writing-files#reading-from-a-file)。 –

回答

1

使用Windows.Storage命名空间,并按照创建,访问和其他操作,如在这些文件夹和文件上UWP下面的代码。

  //Get Installation Folder for current application 
      StorageFolder rootFolder = ApplicationData.Current.LocalFolder; 

      //Create a folder in the root folder of app if not exist and open if exist. 
      StorageFolder Folder = await rootFolder.CreateFolderAsync(yourFolderName, CreationCollisionOption.OpenIfExists); 

      //Craete a file in your folder if not exist and replace it with new file if exist 
      StorageFile sampleFile = await Folder.CreateFileAsync("samplefile.xml", CreationCollisionOption.ReplaceExisting); 

      //Create your text and write it on your configuaration file 
      string yourText = "Your Sample Text or Configuration"; 
      await Windows.Storage.FileIO.WriteTextAsync(sampleFile, yourText); 

之后,您可以再次访问文件,从ReadTextAsync方法读取您的配置值。

  //Read data from file 
      await Windows.Storage.FileIO.ReadTextAsync(sampleFile);