How to load .txt file in Android
Hi, I'm making a Word-based game and I'm loading all the words through smalls .txt files (each files represents a Word Category. e.g: Animals, Food, etc.).
Currently I load them like this:
using System.Collections.Generic;
using System.IO;
using UnityEngine;
public static class WordsLoader
{
public static List<string> words = new List<string>();
public static void LoadWords()
{
DirectoryInfo path = new DirectoryInfo(Application.streamingAssetsPath);
FileInfo[] files = path.GetFiles("*.txt");
foreach (FileInfo file in files)
{
string filePath = file.FullName;
string[] lines = File.ReadAllLines(filePath);
for (int i = 0; i < lines.Length; i++)
{
lines[i] = lines[i].ToUpper();
}
words.AddRange(lines);
}
}
}
And it works perfectly on the Editor, but while testing the .apk on my phone, it doesn't. I soon found out that Android doesn't load files like these but I couldn't get anything that I searched to work.
This is my first time making a Word game, a mobile one and using files, so I could have not done this the most optimal way, but it's just for learning.
Note: The foreach part is VERY important since I store each word per line, which is a very nice and simple way of getting them into the List, so I would like to keep that (well basically the FileInfo class that gives me that).
Thanks!