greenboy1 发表于 2013-1-30 01:12:58

在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》
页: [1]
查看完整版本: 在SDcard上创建sqlite数据库