我在我的Android应用程序中使用sqlite数据库.我想将数据库下载到pc.任何人都可以告诉我该怎么做?
解决方法:
如果您的应用程序在模拟器中,您只需使用DDMS并打开/data/data/your.package.name/databases.
如果您的移动应用程序.这是我将数据库复制到sdcard根文件夹的方法.
/** The name of the database file */
static final String DATABASE_NAME = "mydatabase.db";
static final String DATABASE_NAME_FULL = "/data/data/com.my.application/databases/" + DATABASE_NAME;
public static boolean backUpDataBase(Context context){
boolean result = true;
// Source path in the application database folder
String appDbPath = DATABASE_NAME_FULL;
// Destination Path to the sdcard app folder
String sdFolder = Environment.getExternalStorageDirectory().getAbsolutePath() + "/" + DATABASE_NAME;
InputStream myInput = null;
OutputStream myOutput = null;
try {
//Open your local db as the input stream
myInput = new FileInputStream(appDbPath);
//Open the empty db as the output stream
myOutput = new FileOutputStream(sdFolder);
//transfer bytes from the inputfile to the outputfile
byte[] buffer = new byte[1024];
int length;
while ((length = myInput.read(buffer))>0){
myOutput.write(buffer, 0, length);
}
} catch (IOException e) {
result = false;
e.printstacktrace();
} finally {
try {
//Close the streams
if(myOutput!=null){
myOutput.flush();
myOutput.close();
}
if(myInput!=null){
myInput.close();
}
} catch (IOException e) { }
}
return result;
}
你需要在manifest.xml中使用它
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。