
是否有可能在路径“ //data/system/accounts.db”中获取android中数据库文件的路径
在我的应用程序中,我想使用此数据库,但不获取其路径.
如果我进行硬编码并删除文件,我就能做到.但是我想作为数据库访问它,以便我可以删除表.
任何帮助将是可观的.
我试过的代码:
private sqliteDatabase db; file dbfile = mContext.getDatabasePath("accounts.db"); if (dbfile.exists()) { db = sqliteDatabase.openorCreateDatabase(dbfile, null); db.execsql("DROP table IF EXISTS accounts"); db.setVersion(db.getVersion()+1); }解决方法:
您可以使用androID.os.Environment.getDataDirectory()获取数据目录的路径.
如果数据库不在应用程序的数据目录中,请不要使用mContext.getDatabasePath.
另见
Is it possible to move the internal DB to the SDCard?
如果要搜索,请通过以下方式进行递归文件搜索:
private voID searchfile(String startingPoint) { files[] files = file("/data").Listfiles(); for (file f:files) { if (f.isDirector) searchfile(f); else if (f.getname().equals("accounts.db")) { // delete db here... // and exit the search here... } } }并检查其中是否包含accounds.db.如果到达另一个子目录,则以子文件夹为起点递归调用自己的函数,依此类推.
但是,请确保您对设置为开始搜索的相关文件夹具有读取权限.
总结以上是内存溢出为你收集整理的如何访问Android中不同应用程序的数据库或文件的路径全部内容,希望文章能够帮你解决如何访问Android中不同应用程序的数据库或文件的路径所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)