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이이있다!
누구든지 내가 뭘 잘못하고 있다고 말할 수 있습니까?
을 참조하십시오. 또한 중단 점을 넣고 myimput이 iylooks와 같은 파일을 열 었는지 확인하십시오. 아마도 철자법이나 경로가 잘못되었습니다. – Emile
답장을 보내 주셔서 감사합니다. 경로와 데이터베이스 이름을 확인했는데 괜찮습니다. – Alex
에밀, 내 입력이 열리는 것을 어떻게 볼 수 있습니까? – Alex