Get database path

后端 未结 4 837
我在风中等你
我在风中等你 2020-12-10 00:57

Im new to android and I want to create kind of CRUD with SQLite.

I have a public class DataBaseHelper which have a constructor:

public D         


        
4条回答
  •  攒了一身酷
    2020-12-10 01:34

    To get the path of Sqlite data base

    here I am writing two ways to get the path.

    (1) using custom method

    public String getDbPath(Context context,String YourDbName)
    {
        return context.getDatabasePath(YourDbName).getAbsolutePath();
    }
    

    (2) using File class

      File path=context.getDatabasePath("YourDbName");
      String db_path=path.getAbsolutePath();
      Log.i("Path:",db_path);
    

    even you will see the both code ...then both code is same, 1st one is the shortcut method to get the database path, and it's occupy the less memory compare to second option.

提交回复
热议问题