2014-05-15 1 views
0

내 문제는 데이터베이스가 전화 경로에 자산 폴더에서 복사 할 때 내 응용 프로그램이 항상 실패 할 것입니다 실패로드 데이터베이스의 FileOutputStream은

atnRoutenplaner.sqlite3 

내 전송을위한 코드 :

private void copyDataBase() throws IOException{ 

    //Open your local db as the input stream 
    InputStream myInput = myContext.getAssets().open(DB_NAME); 

    // Path to the just created empty db 
    String outFileName = DB_PATH + DB_NAME; 
    File sampleFile = new File(outFileName); 
    //Open the empty db as the output stream 
    OutputStream myOutput = new FileOutputStream(outFileName); 

    //transfer bytes from the inputfile to the outputfile 
    byte[] buffer = new byte[1024]; 
    int length; 
    while ((length = myInput.read(buffer)) > 0) { 
     myOutput.write(buffer, 0, length); 
    } 

    //Close the streams 
    myOutput.flush(); 
    myOutput.close(); 
    myInput.close(); 

} 

답변

0

이 시도

public void CopyDataBaseFromAsset() throws IOException{ 
     InputStream in = ctx.getAssets().open("mycontacts"); 
     Log.e("sample", "Starting copying"); 
     String outputFileName = DATABASE_PATH+DATABASE_NAME; 
     File databaseFile = new File("/data/data/com.copy.copydatabasefromasset/databases"); 
     // check if databases folder exists, if not create one and its subfolders 
     if (!databaseFile.exists()){ 
      databaseFile.mkdir(); 
     } 

     OutputStream out = new FileOutputStream(outputFileName); 

     byte[] buffer = new byte[1024]; 
     int length; 


     while ((length = in.read(buffer))>0){ 
       out.write(buffer,0,length); 
     } 
     Log.e("sample", "Completed"); 
     out.flush(); 
     out.close(); 
     in.close(); 

    } 
+0

죄송합니다. 이유를 이해할 수 없습니다. atnRoutenplaner.sqlite를 사용하여 이전 데이터베이스를 사용했습니다. 어쩌면 결말일까요? – user3552619