Windows IoT Raspberry Pi 3 c# 创建 .txt 文件 [英] Windows IoT Raspberry Pi 3 c# Create .txt file

查看:59
本文介绍了Windows IoT Raspberry Pi 3 c# 创建 .txt 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将 Rasp Pi 3 与 Win IoT 结合使用.我正在尝试使用 Data & 创建一个 .txt 文件.时间作为文件名.但是,似乎我无法创建 .txt 文件.

I am using Rasp Pi 3 with Win IoT. I am trying to create a .txt file with Data & time as file name. However, it seems that I can't create .txt file.

我正在通过按下按钮来生成 log.txt 文件进行测试.按下按钮后,没有错误信息.当我读取 U 盘时,创建了 Log 文件夹,但没有 Log.txt 文件.

I am testing out by pressing a button to generate a log.txt file. After pressing the button, there is no error message. When I read the USB drive, the Log folder was created but there is not Log.txt file.

private async void Btn_Click(object sender, RoutedEventArgs e)
    {
        var removableDevices = KnownFolders.RemovableDevices;
        var externalDrives = await removableDevices.GetFoldersAsync();
        var drive0 = externalDrives[0];

        var logFolder = await drive0.CreateFolderAsync("Log");
        var logFile = await logFolder.CreateFileAsync("Log.txt");

        var byteArray = new byte[] { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77 };
        using (var sourceStream = new MemoryStream(byteArray).AsRandomAccessStream())
        {
            using (var destinationStream = (await logFile.OpenAsync(FileAccessMode.ReadWrite)).GetOutputStreamAt(0))
            {
                await Windows.Storage.Streams.RandomAccessStream.CopyAndCloseAsync(sourceStream, destinationStream);
            }
        }
    }

谢谢.

推荐答案

您需要在应用清单中为 .txt 添加文件类型关联声明,如下所示:

You need to add File Type Association declarations for .txt in your app manifest like this:

这篇关于Windows IoT Raspberry Pi 3 c# 创建 .txt 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆