参考资料
1.微软官方介绍 saving and finding your files https://developer.microsoft.com/en-us/windows/mixed-reality/saving_and_finding_your_files
2.自定义文件存取方法 http://longqian.me/2017/02/08/hololens-file-transfer/
按照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,方便后续操作。
时间: 2024-10-07 06:47:17