方法如下:
private void export() {
String picturesDirPath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).getAbsolutePath();
File dbDir = new File(picturesDirPath, "Cs");
if (!dbDir.exists()) {
dbDir.mkdirs();
}
File targetFile = new File(dbDir, "Cs.db");
File sourceFile = new File("/data/user/0/com.hisome.youractivity/databases/Cs.db");
try (FileInputStream fis = new FileInputStream(sourceFile);
FileOutputStream fos = new FileOutputStream(targetFile)) {
byte[] buffer = new byte[1024];
int length;
while ((length = fis.read(buffer)) > 0) {
fos.write(buffer, 0, length);
}
} catch (IOException e) {
e.printStackTrace();
}
}
DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(context, "your-database-name.db", null);
import android.content.Context;
public class DatabaseHelper {
public static String getDatabasePath(Context context, String dbName) {
return context.getDatabasePath(dbName).getPath();
}
}
String dbPath = DatabaseHelper.getDatabasePath(yourApplicationContext, "your-database-name.db");;