博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Hololens创建、读取、删除本地文件,为解决的坑
阅读量:6876 次
发布时间:2019-06-26

本文共 1275 字,大约阅读时间需要 4 分钟。

参考资料

1.微软官方介绍 saving and finding your files 

2.自定义文件存取方法  

 

以下是之前采用的方法,属于网上关于UWP存取文件推荐的方法。

按照2中的方法,可以将文件保存在 ApplicationData.Current.RoamingFolder文件加下,这样从网页连接hololens时就可以拷贝出来了,比较方便。

写入与读取的方法可以采用uwp提供的方式,示例如下

写入
StorageFolder folder;        folder = ApplicationData.Current.RoamingFolder;        StorageFile file = await folder.CreateFileAsync("position.txt", CreationCollisionOption.ReplaceExisting);        using (StorageStreamTransaction transaction = await file.OpenTransactedWriteAsync())        {            using (DataWriter dataWriter = new DataWriter(transaction.Stream))            {                dataWriter.WriteString(positionstring);                transaction.Stream.Size = await dataWriter.StoreAsync();                await transaction.CommitAsync();            }        }

读取

StorageFolder folder;        folder = ApplicationData.Current.RoamingFolder;StorageFile file = await folder.TryGetItemAsync("position.txt") as StorageFile;if (file != null)        {            string positionstring = await FileIO.ReadTextAsync(file);}

读取时用的folder.TryGetItemAsync,这个方法如果打开文件失败的话会返回null,方便后续操作。

在用于hololens读取自定义的文件时,总是随机的出现闪退现象,全是在读取、写入、删除文件的地方出问题。最后用了system.io.File方法重写的,居然就再也没出闪退的问题。虽然不知道原理不过也算是解决了,但是如果自定义的文件过大的话也许会有问题。

 

转载于:https://www.cnblogs.com/bwzydr/p/6858370.html

你可能感兴趣的文章
centos 查询mysql配置文件位置
查看>>
Eclipse IDE 使用技巧(一)
查看>>
Jquery 遍历 Table;遍历CheckBox ;遍历Select;全选/全不选
查看>>
day14 内置函数二
查看>>
Sequelize-nodejs-2-basic usage
查看>>
XVI Open Cup named after E.V. Pankratiev. GP of Ekaterinburg.
查看>>
iOS-中app启动闪退的原因
查看>>
iOS--高级技术
查看>>
struct内存对齐
查看>>
Fiddler使用教程
查看>>
模式识别之车牌识别项目---车牌识别资料大全
查看>>
基于MeanShift的目标跟踪算法及实现
查看>>
linux 查看日志
查看>>
《CSS世界》读书笔记(八)
查看>>
Spark学习之路 (十三)SparkCore的调优之资源调优JVM的基本架构
查看>>
redis-cluster介绍
查看>>
web cookie and session
查看>>
构建一个通用的php验证的函数
查看>>
面向对象(单列模式)
查看>>
SpringMVC 实现文件下载
查看>>