- Home /
How to use UnityWebRequest to access local text file on Andorid build
Hello,
I'm trying to make a simple app that chooses a random workout from a text file and will be build on Android. I've read that you can't access files with streamreaders directly because of the way the apk is compressed on Android.
I've tried using UnityWebRequest to no avail. Maybe I'm not understanding the documentation, but I can't figure out how to access a local text file with UnityWebRequest. When I load the file path, I get this error:
FileNotFoundException: Could not find file "D:\Unity Projects\WorkoutApp v2\UnityEngine.Networking.UnityWebRequest"
Here is my code:
void Awake()
{
UnityWebRequest workoutAssets = UnityWebRequest.Get("file://Assets/workouts.txt");
string workoutsFile = workoutAssets.ToString();
workoutList = ReadWorkouts(workoutsFile);
}
public List<string> ReadWorkouts(string workoutsFile)
{
List<string> fileDataList = new List<string>();
using (StreamReader sr = new StreamReader(workoutsFile))
{
string line;
while ((line = sr.ReadLine()) != null)
{
fileDataList.Add(line);
}
}
return fileDataList;
}
I'd really appreciate some guidance here!
Thank you!
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Download multiple files from server 2 Answers
Loading TextAsset returns null 1 Answer