android程序读取项目中已经存在的数据库
String databaseFilename = DATABASE_PATH + "/" + DATABASE_NAME; |
02 |
File dir = new File(DATABASE_PATH); |
03 |
if (!dir.exists()) |
04 |
dir.mkdir(); |
05 |
if (!( new File(databaseFilename)).exists()) { |
06 |
InputStream is = context.getResources().openRawResource(R.raw.jobexam); |
07 |
FileOutputStream fos = new FileOutputStream(databaseFilename); |
08 |
byte [] buffer = new byte [ 8192 ]; |
09 |
int count = 0 ; |
10 |
while ((count = is.read(buffer)) > 0 ) { |
11 |
fos.write(buffer, 0 , count); |
12 |
} |
13 |
fos.close(); |
14 |
is.close(); |
15 |
} |
16 |
db = SQLiteDatabase.openOrCreateDatabase(databaseFilename, null ); |