2017-12-25 23 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