将旧数据库替换为新数据库

Replacing databases from previous to new one

如何将新的数据库文件替换为以前的数据库文件? 我以前的数据库在文件夹中:

 string filepath = Application.persistentDataPath + "/" + "Martyr.db";

我的应用代码:

string filePath = Application.persistentDataPath + "/" + "Martyr.db";
string disPath;
if (!File.Exists(filePath))
        {
            disPath = System.IO.Path.Combine(Application.streamingAssetsPath, "Martyr.db");
            WWW loadDB;
#if UNITY_ANDROID
            {
                loadDB = new WWW(disPath);
            }

#if UNITY_EDITOR
            {
                loadDB = new WWW("file://" + Application.streamingAssetsPath + "/Martyr.db");
            }
#else
            {loadDB=new WWW(dispath);}
#endif
#endif
            while (!loadDB.isDone)
            {
            }
            File.WriteAllBytes(filePath, loadDB.bytes);
        }

您可以简单地删除旧的数据库文件并编写一个新的。

            string filePath = Application.persistentDataPath + "/" + "Martyr.db";
            string disPath;
            if (File.Exists(filePath)) {
                File.Delete(filePath);
            }

            disPath = System.IO.Path.Combine(Application.streamingAssetsPath, "Martyr.db");
            WWW loadDB;
#if UNITY_ANDROID
            {
                loadDB = new WWW(disPath);
            }

#if UNITY_EDITOR
            {
                loadDB = new WWW("file://" + Application.streamingAssetsPath + "/Martyr.db");
            }
#else
            {loadDB=new WWW(dispath);}
#endif
#endif
            while (!loadDB.isDone) {
            }
            File.WriteAllBytes(filePath, loadDB.bytes);