How to load a .xml file in Android?

I place a “strings.xml” file in the StreamingAssets folder because I want to load some parameters from it. But I failed to load this .xml file. I tried to load this file by System.IO, the path of it is Application.streamingAssetsPath + “/XML/strings.xml”, and failed. Also, I tried to load this file by WWW, the path of it is “file://”+Application.streamingAssetsPath + “/XML/strings.xml”, and failed.

Also, I notice that the WWW is already obsolete in Unity2018.3. So what’s the best way to load this config file in Android(API>=24)?

UnityWebRequest is a replacement for WWW.

I figured out that my problem was caused by the utf-8 BOM of the .xml file. And I should use WWW class, the path is Application.streamingAssetsPath + “/XML/strings.xml”, to open any file in the StreamingAssets folder.

You can also read streaming assets using UnityWebRequest (since 2017.1).

1 Like