【问题标题】:How can I upload and read a file on a raspberry pi running Windows 10 IoT如何在运行 Windows 10 IoT 的树莓派上上传和读取文件
【发布时间】:2017-08-17 13:51:08
【问题描述】:

我已经构建了一个应用程序,它可以读取配置文件并加载基于 xml 的字典。 我想要的是不需要将该文件添加到程序中。相反,我希望能够上传到 pi3,然后告诉程序刷新并读取我上传的文件。它将包含在代码中的文件加载到一个不起眼的文件夹中。
如何将代码中的路径上传并指定到更容易访问的文件夹。

提前致谢

【问题讨论】:

标签: c# raspberry-pi3 windows-10-iot-core


【解决方案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);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-03-27
    • 1970-01-01
    • 2017-01-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多