Database 从应用程序导入和导出数据库
我正在与android studio和sqlite合作。每天早上我都需要从手机的内存中导入我的数据库,然后每天下午导出到同一个文件夹中 目前,我在资产,但我需要每天收费Database 从应用程序导入和导出数据库,database,memory,import,android-studio,export,Database,Memory,Import,Android Studio,Export,我正在与android studio和sqlite合作。每天早上我都需要从手机的内存中导入我的数据库,然后每天下午导出到同一个文件夹中 目前,我在资产,但我需要每天收费 任何帮助或手册都会大有帮助。我用它将我的数据库应用程序复制到内存中 public boolean Backup_bd(String Motivo,Context Contexto) { boolean Correcto = false; String message; try { bo
任何帮助或手册都会大有帮助。我用它将我的数据库应用程序复制到内存中
public boolean Backup_bd(String Motivo,Context Contexto) {
boolean Correcto = false;
String message;
try {
boolean sdDisponible = false;
boolean sdAccesoEscritura = false;
//Comprobamos el estado de la memoria externa (tarjeta SD)
String estado = Environment.getExternalStorageState();
if (estado.equals(Environment.MEDIA_MOUNTED)) {
sdDisponible = true;
sdAccesoEscritura = true;
} else if (estado.equals(Environment.MEDIA_MOUNTED_READ_ONLY)) {
sdDisponible = true;
sdAccesoEscritura = false;
} else {
sdDisponible = false;
sdAccesoEscritura = false;
}
//////////////////////////////////////////////////////////
//Path aplication bd
final String inFileName = "/data/data/your_proyect_name/databases/your_database_name";
File dbFile = new File(inFileName);
FileInputStream fis = new FileInputStream(dbFile);
//
String bdExportada = "/www/bd/your_database_name";
String sCarpeta = Environment.getExternalStorageDirectory() + "/www";
File Carpeta = new File(sCarpeta);
if (Carpeta.exists()) {
} else {
Carpeta.mkdir();
}
String sCarpeta_bd = Environment.getExternalStorageDirectory() + "/www/bd";
File Carpeta_bd = new File(sCarpeta_bd);
if (Carpeta_bd.exists()) {
} else {
Carpeta_bd.mkdir();
}
String outFileName = Environment.getExternalStorageDirectory() + bdExportada;
// Open the empty db as the output stream
OutputStream output = new FileOutputStream(outFileName);
// Transfer bytes from the inputfile to the outputfile
byte[] buffer = new byte[1024];
int length;
while ((length = fis.read(buffer)) > 0) {
output.write(buffer, 0, length);
}
// Close the streams
output.flush();
output.close();
fis.close();
//Toast.makeText(Contexto, "Copia realizada satisfactoriamente.", Toast.LENGTH_LONG).show();
Correcto = true;
/////////////////////////////////////////////////////////
} catch (Exception ex) {
message = ex.getMessage();
Toast.makeText(Contexto, message, Toast.LENGTH_LONG).show();
}
return Correcto;
}
你到底在找什么?将数据库转储放在何处?请澄清您的问题。我的android应用程序是桌面应用程序的补充,所有这些天都在从我的桌面应用程序创建一个新的sqlite数据库,我需要将我的手机连接到usb端口并将数据库加载到我的应用程序中。目前,我将数据库放置在资产中,然后将数据库放置在SD卡的某个位置。并将其从/复制到那里,而不是从资产中复制。