unity 內勾選 RemovableStorage 選項或 Package.appxmanifest 勾選 可移動存儲 選項
uwp app IO操作用 StreamReader 會提示沒有權限,如:
1 using UnityEngine; 2 using System.IO; 3 public class test : MonoBehaviour 4 { 5
6 void Start () 7 { 8 string path = Path.Combine(Application.streamingAssetsPath, "test.txt"); 9 StreamReader s = new StreamReader(path); 10 string end = s.ReadToEnd(); 11 Debug.Log(end); 12 } 13
14 }
結果會報錯,uwp應用的IO操作需要用到 StorageFile 類(導出uwp工程后添加 Windows.Storage 命名空間才能夠使用StorageFile類),或者使用 File 類的靜態方法,www 讀取還沒嘗試過
參考資料:win10 UWP讀寫文件