【问题标题】:Creating txt file on hololens在 hololens 上创建 txt 文件
【发布时间】:2017-05-17 03:10:50
【问题描述】:

我正在尝试在 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 上的应用程序会冻结一段时间然后关闭。代码有问题吗?知道发生了什么吗? 提前致谢

【问题讨论】:

标签: c# unity3d hololens


【解决方案1】:

在 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
}

【讨论】:

  • 一个非常有用且正确的答案。非常感谢
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-07-26
  • 1970-01-01
  • 1970-01-01
  • 2013-09-02
  • 2013-01-31
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多