san*_*dee 4 android android-sqlite
我的应用程序中有一个SQLite数据库.当我在文件资源管理器中检查数据库是否已创建时,该data文件夹中没有任何数据库文件.它甚至没有显示使用该adb shell命令.这是否意味着尚未创建数据库?关于如何解决这个问题的任何建议?
如果您使用的是实际设备,除非您使用手机,否则您将无法从外部查看或访问它.
如果您使用的是模拟器,DDMS视图将允许您导航到它并从那里拉出它.
或者,您可能会遇到创建数据库的问题.没有看到你的代码,我们无法分辨.
编辑
如果要从真实设备中获取文件,则需要实现一种方法将其从数据目录复制到您有权访问的位置(例如SD卡).这样可以解决问题:
public void backup() {
try {
File sdcard = Environment.getExternalStorageDirectory();
File outputFile = new File(sdcard,
"YourDB.bak");
if (!outputFile.exists())
outputFile.createNewFile();
File data = Environment.getDataDirectory();
File inputFile = new File(data, "data/your.package.name/databases/yourDB");
InputStream input = new FileInputStream(inputFile);
OutputStream output = new FileOutputStream(outputFile);
byte[] buffer = new byte[1024];
int length;
while ((length = input.read(buffer)) > 0) {
output.write(buffer, 0, length);
}
output.flush();
output.close();
input.close();
} catch (IOException e) {
e.printStackTrace();
throw new Error("Copying Failed");
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4222 次 |
| 最近记录: |