- Home /
Load text file on Streaming assets in Android
On unity documents, Streaming assets are pressed to jar file.
I played my game on android, My text file on streaming assets did not be loaded.
string path = Application.streamingAssetsPath + "/" + filename;
if(Application.platform == RuntimePlatform.Android)
{
path = "jar:file://" + Application.dataPath + "!/assets/" + filename;
}
if (File.Exists(path))
{
FileStream file = new FileStream (path, FileMode.Open, FileAccess.Read);
StreamReader sr = new StreamReader( file );
string str = null;
str = sr.ReadLine ();
sr.Close();
file.Close();
return str;
}
else
{
return null;
}
this is my code of read file.
I need your help T.T
Answer by pitimoi · Aug 16, 2013 at 01:20 PM
Hi,
I think the path Application.streamingAssetsPath + "/" + filename;
is still valid on android, you don't need to use something else to access your data on android.
Anyway, try to read your file using a WWW instead of using a filestream, it should works better with unity.
Thanks for answer. I want to ask if I use www,how can I code that. www data = new www( "jar:file://" + Application.dataPath + "!/assets/" +filename); like this???
$$anonymous$$mmh, I don't have any project to test right now, but what I would try is :
WWW data = new WWW(Application.strea$$anonymous$$gAssetsPath+"/"+filename);
yield return data;
if(string.IsNullOrEmpty(data.error))
{
myText = data.text;
}
You should place it into a Coroutine to use WWW with Unity.
Answer by ereneld · Feb 22, 2017 at 08:31 AM
it is always better to use with path.combine
string filename = "";
Path.Combine(Application.streamingAssetsPath, filename);
Answer by Gunhi · Jun 29, 2017 at 04:20 AM
"It is not possible to access the Strea$$anonymous$$gAssets folder on WebGL and Android platforms"
Answer by uzairamirs · Apr 12, 2018 at 12:16 PM
@sanmn19 bro/sir, can you please help me? I am stuck in this.. I am trying to access streaming assets in an apk and failing for 3 days.. If you could help it would be very kind of you.
Your answer
Follow this Question
Related Questions
android browse and read text files 1 Answer
High score local [Android] 1 Answer
Opening data file from asset folder 2 Answers
Reading from a file not working on Android 0 Answers
How to set persistent data path to sdcard on android 0 Answers