c# - 在 hololens 上创建 txt 文件

标签 c# unity3d hololens

我正在尝试在全息镜头上创建一个应用程序,该应用程序创建并写入文本文件以记录用户的输入。目前,我一直在尝试制作文件并从文件资源管理器或一个驱动器访问它。这是我的方法:

public void createFile()
    {
#if WINDOWS_UWP
        Task task = new Task(
        async () =>
        {
        testText.text="hi";
        StorageFolder storageFolder = ApplicationData.Current.LocalFolder;
        StorageFile textFileForWrite = await storageFolder.CreateFileAsync("Myfile.txt");
        });
        task.Start();
        task.Wait();
#endif
    }

这基本上就是我在这里找到的:https://forums.hololens.com/discussion/1862/how-to-deploy-and-read-data-file-with-app ,但是当我尝试运行该方法时,hololens 上的应用会卡住一会儿然后关闭。代码有问题吗?知道发生了什么事吗? 提前致谢

最佳答案

在 Unity 中,您可以使用 Application.persistentDataPath: https://docs.unity3d.com/ScriptReference/Application-persistentDataPath.html

在设备门户/文件资源管理器中,它映射到 LocalAppData/YourApp/LocalState。下面的代码将在那里写入“MyFile.txt”。

using System.IO;

string path = Path.Combine(Application.persistentDataPath, "MyFile.txt");
using (TextWriter writer = File.CreateText(path))
{
    // TODO write text here
}

关于c# - 在 hololens 上创建 txt 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44014883/

相关文章:

javascript - 如何在浏览器中拍照并使用http协议(protocol)上传?

unity3d - 在 Microsoft HoloLens 上查找网格中的固定点

c# - 新的输入系统不再触发任何东西

c# - WebClient 在 Windows Phone 8.1 上不存在?下载网站的html

c# - Razor View 引擎中有设计 View 吗?

c# - 如果 .Count == 0 条件运算符不显示

c# - 为什么Unity3D会出现cs0433错误?我该如何解决?

c++ - 读取dll文件中的文本文件

c# - Hololens - UserConsentVerifier 不适用于 Hololens 第一代

c# - 使用 UserProfileManager 获取随机用户