2017-12-25 16 views
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); 
     } 

答えて

0

あなたは単にあなたの古いDatabasefileを削除し、新しいものを書くことができます。

  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); 
+0

これは機能しません。 このエラーが発生しましたIOException:パス上の共有違反 – Seyed

+0

データベースを削除しようとしていますか?それはどんなファイルストリームによって開かれていますか? –

+0

ありがとうございます。そうだと思います。私のデータベースは公開されていました。 – Seyed

関連する問題