I need to read some lines from .txt file and after ceratain string(“co_wypisac”) return the remaining part of the line as a string. It works perfectly while running on unity, but after building and exporting to android device the data from file is not visible (no display box). I do not want to use XML for few reasons. Anyone got an idea?
stream filetoread=“file.txt”;
StreamReader odczytaj = new StreamReader(Application.dataPath + “/Language_files/” + filetoread);
The reason is simple the target file is not included in the build since the file didn’t have any linked reference with the scene. So wat you have to do is make unity force include the file.
note that files inside Resources folder is always included in build.
so all u have to do is make a folder called Resources under assets folder and move the language folder into it.
so now you hav to,pass path as Application.datapath+“Resources/Language_files/”+filetoread
Edit sorry for the blunder I have made,
2 points to be mentioned, In android, the file you have kept in any of the project folder cannot be accessed seperately. Because of this, You wont be able to use streamreader.
Files in resource folder can be accessed and loaded at runtime. but not using stream reader. you have to load it as a text asset and get the whole content of file loaded.
one thing to note is that the file should be of .txt extension for loading it using TextAsset.
//the file name is testfile.txt so im using here as testfile
TextAsset odczytaj = Resources.Load("Language_files/testfile") as TextAsset;
string[] linesFromfile = odczytaj.text.Split("
The StreamingAssets folder is also included in the build, but the files are not loaded into Unity. It is a good option to use with StreamReader, but it does not work with Resources.Load
Great! thanks
– gmonks