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