Hololens創建、讀取、刪除本地文件
阿新 • • 發佈:2017-05-15
方式 finding ati blog color http tps ans 網頁
參考資料
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,方便後續操作。
Hololens創建、讀取、刪除本地文件