UnityAndroid 获取根目录文件


1. 在Unity打包时获取SD权限
2. Android根目录为 "/storage/emulated/0";

代码:

   if (Directory.Exists("/storage/emulated/0/xxx"))
        {          
            StartCoroutine(PostRequest("/xxx/TestLoad.txt", "message"));
            if (File.Exists("/storage/emulated/0/xxx/TestLoad.txt"))
            {           
                try
                {
                    text.text = File.ReadAllText("/storage/emulated/0/xxx/TestLoad.txt");
                }
                catch (System.Exception e)
                {
                    text.text = e.Message;
                    throw;
                }           
            }  
        }

 

posted @ 2021-11-01 16:55  D个人笔记  阅读(994)  评论(0编辑  收藏  举报