- Home /
How do I read unicode text file on IOS from resources folder?
Hi :) I have used AES to encrypt a series of properties and have stored them in a text file that I have placed in the resources folder of my project. I can read the text file correctly in the editor using...
string[] text = File.ReadAllLines ("Assets/Resources/Test.txt", Encoding.Unicode);
...but I can't figure out how to do it on an IOS device. I have searched a lot and tried a few things but failed. Can someone please point me in the right direction?
Thanks :)
Answer by Tarlius · Sep 20, 2013 at 04:23 AM
You need to use Resources.Load in a build. If you open the bundle on the device (with iExplorer/etc) you will see that that file does not exist! All files in any folder below a "Resources" folder anywhere in the Assets folder are put into a special Unity file (pre-imported to a native binary format where applicable for faster loading) at build time.
TextAsset file = Resources.Load("Test.txt") as TextAsset;
string text = file.text; // If that doesn't work, you can get the raw bytes with .bytes and convert
Since you are using encryption, it might be better to use .bytes and just not bother encoding the file, to save you having to reverse the encoding, by the way. I believe the encryption libraries work with byte arrays/streams by default anyway.