2011-04-13 4 views
0

데이터베이스 파일을 드로어 블 폴더에 저장 한 다음 SD 카드에 백업을 만들고 싶습니다. 이 작업을 수행하는 동안 drawable 폴더에 대해 어떤 경로를 지정해야하는지 findind 문제입니다. 나는이 일을하고있다 :데이터베이스 저장 및 검색

시도 {사전에

 File sd = Environment.getExternalStorageDirectory(); 

     File data = Environment.getDataDirectory(); 

     if (sd.canWrite()) { 
      //db = openOrCreateDatabase("demodatabase.sqlite",SQLiteDatabase.CREATE_IF_NECESSARY,null); 
    currentDBPath = "//drawable//demodatabase.sqlite"; 



    db=openOrCreateDatabase(uri.toString(), 0, null); 
     System.out.println("====="+ currentDBPath); 
     backupDBPath = "{demodatabase.sqlite}"; 

     File currentDB = new File(data, currentDBPath); 

     File backupDB = new File(sd, backupDBPath); 

     if (currentDB.exists()) { 

     FileChannel src = new FileInputStream(currentDB).getChannel(); 

     FileChannel dst = new FileOutputStream(backupDB).getChannel(); 

     dst.transferFrom(src, 0, src.size()); 

     src.close(); 

     dst.close(); 

     } 

     } }catch (Exception e) {} 

고맙습니다.

답변

0

당신이하지 드로어 블 폴더에 있지만 자산 폴더에 이러한 파일을 둘 것입니다 방금 내가 널 포인터 예외를 얻고있다

context.getAssets().open("demodatabase.sqlite") 
+0

을 사용하여 이러한 파일에 대한 입력 스트림을 얻을 수 있습니다, 문맥이 고려되지 값 ... 왜 그렇게?] – Piyush

+0

수퍼 클래스로 SQLiteOpenHelper 클래스를 사용하고 있습니까? – senola

+0

아니요, 그냥 활동을 확장 중입니다 ..... – Piyush

관련 문제