如何查看Android手机的SQLite数据库 [英] How to view sqlite database in android phone
本文介绍了如何查看Android手机的SQLite数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经在系统上连接的设备。但我无法看到我的数据库文件,探索DDMS的。有没有简单的方法,所以我可以从Android的设备获取数据库文件?
解决方案
私人无效importDB(){
尝试 {
文件SD = Environment.getExternalStorageDirectory();
文件数据= Environment.getDataDirectory();
如果(sd.canWrite()){
字符串currentDBPath =//数据//+<包名称>
+//数据库//+<数据库名称>;
字符串backupDBPath =<备份数据库文件名>中; //从SD目录。
文件的某个backupdb =新的文件(数据,currentDBPath);
文件currentDB =新的文件(SD,backupDBPath);
FileChannel SRC =新的FileInputStream(currentDB).getChannel();
FileChannel DST =新的FileOutputStream(某个backupdb).getChannel();
dst.transferFrom(源,0,src.size());
src.close();
dst.close();
Toast.makeText(getApplicationContext(),导入成功!,
Toast.LENGTH_SHORT).show();
}
}赶上(例外五){
Toast.makeText(getApplicationContext(),导入失败!,Toast.LENGTH_SHORT)
。显示();
}
}
私人无效exportDB(){
尝试 {
文件SD = Environment.getExternalStorageDirectory();
文件数据= Environment.getDataDirectory();
如果(sd.canWrite()){
字符串currentDBPath =//数据//+<包名称>
+//数据库//+<数据库名称>;
字符串backupDBPath =<目的>中;
文件currentDB =新的文件(数据,currentDBPath);
文件的某个backupdb =新的文件(SD,backupDBPath);
FileChannel SRC =新的FileInputStream(currentDB).getChannel();
FileChannel DST =新的FileOutputStream(某个backupdb).getChannel();
dst.transferFrom(源,0,src.size());
src.close();
dst.close();
Toast.makeText(getApplicationContext(),备份成功!,
Toast.LENGTH_SHORT).show();
}
}赶上(例外五){
Toast.makeText(getApplicationContext(),备份失败!,Toast.LENGTH_SHORT)
。显示();
}
}
下面是<一href="http://stackoverflow.com/questions/18322401/is-it-posible-backup-and-restore-a-database-file-in-android-non-root-devices/18322762#18322762">reference
I have connected my device at system. but i am not able to view my database in file-explore of DDMS. is there any easy way so i can get database file from android-device?
解决方案
private void importDB() {
try {
File sd = Environment.getExternalStorageDirectory();
File data = Environment.getDataDirectory();
if (sd.canWrite()) {
String currentDBPath = "//data//" + "<package name>"
+ "//databases//" + "<database name>";
String backupDBPath = "<backup db filename>"; // From SD directory.
File backupDB = new File(data, currentDBPath);
File currentDB = new File(sd, backupDBPath);
FileChannel src = new FileInputStream(currentDB).getChannel();
FileChannel dst = new FileOutputStream(backupDB).getChannel();
dst.transferFrom(src, 0, src.size());
src.close();
dst.close();
Toast.makeText(getApplicationContext(), "Import Successful!",
Toast.LENGTH_SHORT).show();
}
} catch (Exception e) {
Toast.makeText(getApplicationContext(), "Import Failed!", Toast.LENGTH_SHORT)
.show();
}
}
private void exportDB() {
try {
File sd = Environment.getExternalStorageDirectory();
File data = Environment.getDataDirectory();
if (sd.canWrite()) {
String currentDBPath = "//data//" + "<package name>"
+ "//databases//" + "<db name>";
String backupDBPath = "<destination>";
File currentDB = new File(data, currentDBPath);
File backupDB = new File(sd, backupDBPath);
FileChannel src = new FileInputStream(currentDB).getChannel();
FileChannel dst = new FileOutputStream(backupDB).getChannel();
dst.transferFrom(src, 0, src.size());
src.close();
dst.close();
Toast.makeText(getApplicationContext(), "Backup Successful!",
Toast.LENGTH_SHORT).show();
}
} catch (Exception e) {
Toast.makeText(getApplicationContext(), "Backup Failed!", Toast.LENGTH_SHORT)
.show();
}
}
Here is the reference
这篇关于如何查看Android手机的SQLite数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文