- Home /
File.ReadAllLines from .txt file in an android build, how does it work?
I have an application which uses the data from a .txt file file.txt. Inside this file there are data-blocks separated by \n.
Now I need to put each line as a string in a string[] lines array. In the editor this is not a problem by doing lines = File.ReadAllLines($"{Application.dataPath}/file.txt}").
But as I am building it for android that's not possible because of the way android stores files inside the .apk of an app.
I tried importing the file as an TextAsset and then load the separate lines in my lines array by using .Split('\n'). This kinda works, but as the file.txt has about 15.000 lines this needs too much time.
With changing Application.dataPath to Application.persistantDataPath it would work but as I am not saving the file.txt first, it cannot be found (or at least I don't know where to put it in Unity for it to be found).
I looked for solutions but I can't find one that uses File.ReadAllLines...
Is there any workaround or way to archive this?
Your answer