- Home /
Download dat and xml file on device
Hi Actually I am working on vuforia with unity3d. I have device database within vuforia from it i find tow files dat and xml. It is loaded in project. I want this dat and xml file from url and download on device at runtime. I can't find how to store this file on device. I have write code for downloading as here: function Start1() { str=str+"start call";
var www = new WWW(url);
while(!www.isDone)
{
str=str+"Progress";
Debug.Log("www progress ");
yield www;
}
if(www.isDone)
{
str=str+"Success";
//str=str+Application.persistentDataPath;
System.IO.File.WriteAllBytes(Application.persistentDataPath,www.bytes);
str=str+"download complete";
Debug.Log("Success");
}
else
{
str=str+"fail";
Debug.Log("Fail");
}
}
Here I reach till str=success but it not function File.WriteAllBytes.I have also tried File.WriteAllBytes("jar:file://"+Application.streamingAssetsPath+"!/assets/",www1.bytes); File.WriteAllBytes("unity3d:file://"+Application.streamingAssetsPath+"!/assets/",www1.bytes); but not succeded. Please help me
Answer by mviuk · Aug 03, 2013 at 09:45 AM
In C#, I'd write this, which works fine:
IEnumerator Start ()
{
using(WWW www = new WWW(url))
{
yield return www;
if(www.isDone && string.IsNullOrEmpty(www.error))
{
string localPath = Path.Combine(Application.persistentDataPath, "myDownloadedFile.txt");
File.WriteAllText(localPath, www.text);
}
}
}
I have try this but not work if i print message for debug after write all text it is not printed.
Write all text function is not complete. Actually i have print one string after write all text is not printed.
but it showing file delay in any devices and platform.