日期:2014-05-16  浏览次数:20395 次

在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》