首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > 其他数据库 >

在SDcard下创建sqlite数据库

2012-08-26 
在SDcard上创建sqlite数据库public SQLiteDatabase createOrOpenDatabase(String dbName){?????? //得到SD

在SDcard上创建sqlite数据库

public SQLiteDatabase createOrOpenDatabase(String dbName){

?????? //得到SDcard路径
??? ??? String sdPath = Environment.getExternalStorageDirectory().getPath();
??? ??? //System.out.println(sdPath);
??? ??? String dbPath = sdPath + dbName;

?????? //创建一个文件
??? ??? File f = new File(dbPath);
??? ??? try {
??? ??? ??? f.createNewFile();
??? ??? } catch (IOException e) {
??? ??? ??? e.printStackTrace();
??? ??? }

????? //创建数据库
??? ??? sdb=SQLiteDatabase.openOrCreateDatabase(f, null);
??? ??? System.out.println("create successfully");
??? ??? return sdb;
??? }

?

在操作中注意要加上SDcard的读写权限

《over》

热点排行