File not readable while on phone

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.

Any help is appreciated, thank you.

Are you sure you have the correct permissions?

How do you mean?

When you have to read things from a phone, you often have to ask for permission to get the file.

Like on Android you need access to phone files. I think you have to declare that on iOS too.

You could try setting Write Permission to External in the player settings for android.

You can see debug messages and more on your phone. Logcat is one of many Android programs to view system messages.

How would I go about doing that?

Done that, doesn’t seem to be working.

Thanks for the recommendation, but unfortunately the problem has been found (Wont read from the file) so I don’t believe that debugs will be required.

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:

Cheers

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.

For sure WWW.text will read a text file all at once.
If you need line by line you should use some other way to divide the text by line endings or so.

Jeez, this isn’t going to be fun. I’ll have to put a character at the end of 1080 lines :X

If you have already your file separated in lines so you should have some “/r/n” character at the end of each line. You may try to use that.

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!