如何在android中从路径中检索数据库名称
我在应用程序目录中有一个名为test.db的数据库。我使用方法“getPath()”检索了路径,该方法给出了db的整个路径。如何从该路径获取数据库的名称。 I ma接收路径a data\test.db。我只需要得到test.db。如何仅从android中的路径检索数据库的名称 提前感谢使用如何在android中从路径中检索数据库名称,android,sqlite,Android,Sqlite,我在应用程序目录中有一个名为test.db的数据库。我使用方法“getPath()”检索了路径,该方法给出了db的整个路径。如何从该路径获取数据库的名称。 I ma接收路径a data\test.db。我只需要得到test.db。如何仅从android中的路径检索数据库的名称 提前感谢使用split()进行字符串拆分 String str=yourpathstring; String[] str1=str.split("/"); String dbname=str1[1]; 试试这个
split()
进行字符串拆分
String str=yourpathstring;
String[] str1=str.split("/");
String dbname=str1[1];
试试这个
String dbpath="yourdbpath";
File f = new File(dbpath);
String dbName = f.getName();
如其他线程中所述,您可以使用:
context.getDatabasePath(DataBaseHelper.dbName)
在您的情况下,如果我理解得很好,名称是test.db;这是正确的方法,我认为你会得到你期望的道路
资料来源:
不管怎样;如果只想从字符串data\test.db中提取名称,则可以:
String path = yourpath;
String dbName = path.substring(path.length - 8, 7)
以这种方式使用子字符串将始终提取最后7个字符
来源:给出错误,因为在str.split(“\”@Android\u程序员\u办公室try back slash str.split(“/”)行插入缺少引号