在Hololens上将数据写入文件 [英] Writing Data into a File on Hololens
问题描述
在我的Hololens应用程序中,我想将数据写入文件,然后可以在设备门户上查看该文件.数据仅包含从特殊对象一次轻敲到另一次轻敲的时间. 问题是,在设备门户中的/LocalAppData/YourApp/LocalState下将不会创建文件
in my Hololens app i want to write data into a file which i can then view over the Device Portal. The Data contains just the time from one airtap on a special object to another airtap. The problem ist that there will be no file created in the Device Portal under /LocalAppData/YourApp/LocalState
预先感谢
乔纳森
public void StopTime()
{
TimeSpan ts = time.Elapsed;
time.Stop();
path = Path.Combine(Application.persistentDataPath, "Messdaten.txt");
using (TextWriter writer = File.CreateText(path))
{
writer.Write(ts);
}
}
推荐答案
我通常使用FileStream
和StreamWriter
并确保已设置FileMode.Create
.
I usually use a FileStream
and a StreamWriter
and make sure the FileMode.Create
is set.
另请参见如何编写文本到文件以获取更多方法
See also How to write text to a file for more approaches
using (var file = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.Write))
{
using (var writer = new StreamWriter(file, Encoding.UTF8))
{
writer.Write(content);
}
}
到目前为止,我在HoloLens上从未遇到任何麻烦.
With that I never had any trouble on the HoloLens so far.
您可能还想使用ts.ToString()
之类的格式来格式化所需的值.
You also might want to use something like ts.ToString()
in order to format the value to your needs.
或者,您也可以尝试Unity的 Windows.File (仅适用于UWP),但您需要输入byte[]
.例如.
Alternatively you could also try Unity's Windows.File (only available for UWP) but than you need to have byte[]
as input. E.g. from here
long c = ts.Ticks;
byte[] d = BitConverter.GetBytes(c);
File.WriteAllBytes(path, d);
这篇关于在Hololens上将数据写入文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!