唉,为啥那次运行这行就直接抛异常啊
database = SQLiteDatabase.openDatabase(“/mnt/sdcard/dic/dic.db”, null, SQLiteDatabase.OPEN_READWRITE );
很是费解,我是想直接打开/mnt/sdcard/dic/dic.db目录下的数据库文件,权限已经加了,dic.db是通过
if (!(new File(“/mnt/sdcard/dic/dic.db”)).exists()) {
// 获得封装dic.db文件的InputStream对象
InputStream is = this.getResources().openRawResource(R.raw.dic);
FileOutputStream fos = new FileOutputStream(“/mnt/sdcard/dic/dic.db”);
byte[] buffer = new byte[8192];
int count = 0;
// 开始复制dic.db文件
while ((count = is.read(buffer)) > 0) {
fos.write(buffer, 0, count);
}
fos.close();
is.close();
}拷贝到SD卡里的啊
database = SQLiteDatabase.openDatabase(“/mnt/sdcard/dic/dic.db”, null, SQLiteDatabase.OPEN_READWRITE );
很是费解,我是想直接打开/mnt/sdcard/dic/dic.db目录下的数据库文件,权限已经加了,dic.db是通过
if (!(new File(“/mnt/sdcard/dic/dic.db”)).exists()) {
// 获得封装dic.db文件的InputStream对象
InputStream is = this.getResources().openRawResource(R.raw.dic);
FileOutputStream fos = new FileOutputStream(“/mnt/sdcard/dic/dic.db”);
byte[] buffer = new byte[8192];
int count = 0;
// 开始复制dic.db文件
while ((count = is.read(buffer)) > 0) {
fos.write(buffer, 0, count);
}
fos.close();
is.close();
}拷贝到SD卡里的啊
这一步
执行完就直接跳到return null;这一行了public SQLiteDatabase SDDB() { SQLiteDatabase database = null;
try {
// 获得dic.db文件的绝对路径 String databaseFilename = DATABASE_PATH + "/" + DATABASE_FILENAME;
// Toast.makeText(getApplicationContext(), databaseFilename,
// Toast.LENGTH_SHORT).show();
File dir = new File(DATABASE_PATH);
// 如果/sdcard/dictionary目录中存在,创建这个目录
if (!dir.exists())
dir.mkdir();
// 如果在/sdcard/dictionary目录中不存在
// dictionary.db文件,则从res\raw目录中复制这个文件到
// SD卡的目录(/sdcard/dictionary) if (!(new File(databaseFilename)).exists()) {
// 获得封装dictionary.db文件的InputStream对象
InputStream is = this.getResources().openRawResource(R.raw.dic);
FileOutputStream fos = new FileOutputStream(databaseFilename);
byte[] buffer = new byte[8192];
int count = 0;
// 开始复制dic.db文件
while ((count = is.read(buffer)) > 0) {
fos.write(buffer, 0, count);
}
fos.close();
is.close();
}
// 打开/sdcard/dictionary目录中的dic.db文件 database = SQLiteDatabase.openDatabase("/mnt/sdcard/dic/dic.db", null, SQLiteDatabase.OPEN_READWRITE );
.show();
return database;
} catch (Exception e) {
return null;
}
}