lancer
1
If I download a file from the internet using WWW, where does it save the file?
EDIT:
When I type:
var www = new WWW(SomeLinkHere);
To download something from the internet where does it save the file when unity is done downloading it?
WWW saves the data into your memory. Once fully loaded you must write the bytes.
Here is a snip it that should get your started:
IEnumerator saveData(){
string fileName = "Name of the file.MAKESUREYOUPUTTHEEXTENSION";
string expPath = "/directory/to/where/you/want/to/save";
WWW www;
www = new WWW(url);
//Debug.Log("Starting Download");
yield return www;
//Debug.Log("Download done");
if (www.error != null){
//Debug.Log ("www error " + www.error);
}
else{
//Debug.Log("Check if the directory exists");
if (!System.IO.Directory.Exists(expPath)) {
//Debug.Log("the directory DIDN'T exist, so lets create it");
System.IO.Directory.CreateDirectory(expPath + "/");
}
//Debug.Log("Saving the file");
byte[] fileBytes = www.bytes;
File.WriteAllBytes(expPath + "/" + fileName, fileBytes);
//Debug.Log("loading level");
//DONE
}
}