2011-01-13 3 views
0

이 코드를 사용하여 "Assets"디렉토리의 "sqlite"데이터베이스를 "/ data/data/my_packname/databases /"디렉토리로 복사합니다. 내 자신의 sqlite 데이터베이스를 사용하는 데 문제가 있습니다

while ((length = myInput.read(buffer)) > 0){ 

라인

에서

public class DataBaseHelper extends SQLiteOpenHelper{ 

    private SQLiteDatabase myDataBase; 

    private final Context myContext; 

    public DataBaseHelper(Context context) { 

    super(context, DATABASE_NAME, null, DATABASE_VERSION); 
     this.myContext = context; 
    } 

    ... 

    private void copyDataBase() throws IOException{ 

    //Open your local db as the input stream 

    AssetManager am = this.myContext.getAssets(); 

    InputStream myInput = am.open(DATABASE_NAME); 


    // Path to the just created empty db 
    String outFileName = DATABASE_PATH + DATABASE_NAME; 

    //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(); 

    } 

     ... 
} 

그러나 난 IOException이이있다!

누구든지 내가 뭘 잘못하고 있다고 말할 수 있습니까?

+0

을 참조하십시오. 또한 중단 점을 넣고 myimput이 iylooks와 같은 파일을 열 었는지 확인하십시오. 아마도 철자법이나 경로가 잘못되었습니다. – Emile

+0

답장을 보내 주셔서 감사합니다. 경로와 데이터베이스 이름을 확인했는데 괜찮습니다. – Alex

+0

에밀, 내 입력이 열리는 것을 어떻게 볼 수 있습니까? – Alex

답변

0

이 링크의 답변 코드를 사용해보십시오. 원래 코드에 대한 변경 사항에 대한 주석이 달려 있습니다. 그래서 당신이 잘못하고있는 것을 쉽게 찾을 수 있습니다. 당신이 당신의 서식을 수정하고 databaseName을가 무엇인지 보여줄 수있는 경우

Database not copying from assets

관련 문제