내 데이터베이스에 문제가 있습니다. 응용 프로그램 시작시 데이터베이스가 자산에서 자동으로로드됩니다. 이미 존재하지 않는 경우에만로드해야하며 (응용 프로그램의 처음 시작) 작동하지 않습니다.데이터베이스가 존재하는지 확인하십시오.
public static boolean copyDBFile(Context context)
{
File dbAbsolutePathFile = new File(dbPath + dbName);
File dbPathFile = new File(dbPath);
//Here we make sure that the directory path for the database exists
if(!dbPathFile.exists()) {
dbPathFile.mkdirs();
}
File dbNameFile = context.getDatabasePath(dbName);
//Here we check whether the database file exists or not. If not, we then create it
if(!dbNameFile.exists()) {
Log.d("database", "copy");
//dbNameFile = new File(dbName);
try {
//Here we call the copyDB() method.
copyDB(context.getAssets().open(dbName), new FileOutputStream(dbPath + dbName));
} catch (FileNotFoundException e) {
} catch (IOException e) {
}
}
return true;
}
private static void copyDB(InputStream inputStream, OutputStream outputStream) {
byte[] buffer = new byte[1024];
int length;
//Here we copy 1K bytes at a time
try {
while((length=inputStream.read(buffer))>0) {
outputStream.write(buffer, 0, length);
}
inputStream.close();
outputStream.close();
} catch (IOException e) {
}
}
는 왜 빈'catch' 블록이 있습니까 데이터베이스 가져 오기 위해이 코드
을 시도해보십시오 여기
내 코드? –무엇이 작동하지 않습니까? 애플리케이션이 전혀 시작되지 않거나 체크 코드가 작동하지 않습니다. – Saqib
몇 분 전에는 비어 있지 않았지만 내용에 정적 방법에 문제가있었습니다. 먼저 catch 블록을 채우기 전에 수정해야합니다. – honiahaka10