I am creating an app which requires access to a file which it reads from. Unfortunately, whenever I try and read from the file it doesn’t return anything. I cannot add debugs because it’s on my phone and I can’t read debugs from it. The code is as follows;
using (StreamReader r = new StreamReader(Application.streamingAssetsPath + "/AIC.txt"))
{
string line;
while ((line = r.ReadLine()) != null)
{
counter++;
bookReader.addLine(line);
}
}
This code works fine on computer, but put into practical use (phone) it doesn’t. I export as APK so that it works on my android phone.
Hi @Zalosath your problem is clear. You are trying to read a file into the StreamingAssets folder in some Android device, but the StreamingAssets folder is not a real folder, indeed that folder is compressed inside the APK.
The only way to access is using WWW. I recommend you to use this asset to simplify your file tasks:
Hi, thanks for your reply. I’m starting to use WWW, and it all works fine when I host the file on pastebin. However, how would I read this line by line? Whenever I attempt to foreach loop over the www.text return it gives me a type mismatch error (Understandable). How would I read this line by line? Thanks.
What type of data is in the file? Might it be possible to have whatever data it is in a json format? That way you could parse it to an object when retrieving it.
Thank you, jemonsuarez, I’ve managed to fix this using WWW. I used Pastebin to host a raw text format and then used WWW with the split method for strings to make this possible, thank you!