Android:SQLite
lastmod 2018-08-17created 2014-03-174 edits
Store structured data in a private database.
Export SQLite database file
To extract the DB (SQLite) file stored by a particular application, use the following function in that project.
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import android.content.Context;
import android.os.Environment;
// ...
public static void copyDb(Context c, String dbName) {
File outDir = c.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS);
String outPath = outDir.getPath() + File.separator + dbName;
FileInputStream fis = null;
FileOutputStream fos = null;
try {
// File("/data/data/your.app.package/databases/your_db.db3");
fis = new FileInputStream(c.getDatabasePath(dbName));
fos = new FileOutputStream(outPath);
while (true) {
int i = fis.read();
if (i != -1) {
fos.write(i);
} else {
break;
}
}
fos.flush();
// DB DUMP SUCCESS.
} catch (Exception e) {
// DB DUMP ERROR.
e.printStackTrace();
} finally {
try {
fos.close();
fis.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
See also
Favorite site
- Android Developer: Storage Options: SQLite Databases
- Using the SQLite database on Android 1
- Android - Pulling SQlite database android device
- Access Android app data without root 2
- Viewing the internal SQLite3 database
- [Recommended] Practical Android development - SQLite