hi guys,
I am new to unity…just try to read and write file in android, and it just read fine but writing failed.
I have try to put the file in “Plugins/Android/Assets” or “StreamingAsstes”, any way it read fine, just can’t write to the persistentDataPath , or say, worte but 0 bytes!!
my code(very simple) :
// i just don't care the file exists or not, just write
string filepath = Application.persistentDataPath + "/" + "testword.bytes";
WWW loadDB = new WWW("jar:file://" + Application.dataPath + "!/assets/" + "testword.bytes");
//GameObject.Find("Canvas").transform.GetChild(0).GetComponent<Text>().text = "read failed ";
while (!loadDB.isDone) {; } //
GameObject.Find("Canvas").transform.GetChild(0).GetComponent<Text>().text = loadDB.text+ "read OK";
/*========untill here, everything is allright, and my Text shows the content and read OK. ===*/
// then save to Application.persistentDataPath
try
{
System.IO.File.WriteAllBytes(filepath, loadDB.bytes); //<<<I checked the new file, it just 0 bytes!!
}
catch (System.Exception e)
{
Debug.LogException(e, this);
GameObject.Find("Canvas").transform.GetChild(0).GetComponent<Text>().text = "error**"+ e.ToString();
}
/*========no exception , but, when I check the file , there is 0 bytes in it.=====*/
Thank you guys, it makes me so crazy (cause I am using Sqlite…simpleSql, it just cannot load any thing)