从先前到新的数据库替换数据库

问题描述 投票:1回答:1

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

 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);
        }
c# file unity3d streamreader
1个回答
0
投票

您只需删除旧的数据库文件并编写一个新的。

            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);
© www.soinside.com 2019 - 2024. All rights reserved.