我有一个Android应用程序,它具有将SQLiteDatabase导出到外部存储中的文件的功能。它在我的手机(Redmi 4X)上运行正常,但在其他手机(如三星SM-J105b)中,当我进行备份时它会崩溃。
这是我的备份代码:
private void backupDB() throws IOException {
String backupDirectory = Environment.getExternalStorageDirectory() + "/FDRMobile/Backups/";
File backupDir = new File( backupDirectory, "");
if (!backupDir.exists()) {
backupDir.mkdirs();
}
final String inFileName = "/data/data/com.scbpfsdgis.fdrmobile/databases/FEMobile.db";
File dbFile = new File(inFileName);
FileInputStream fis = new FileInputStream(dbFile);
Date date = new Date();
DateFormat df = new SimpleDateFormat("YYYY-MM-dd_HHMMSS", Locale.getDefault());
String bakFile = "BAK_" + df.format(date) + ".db";
this.backupFileName = bakFile;
backupDirectory += bakFile;
// Open the empty db as the output stream
OutputStream output = new FileOutputStream(backupDirectory);
// 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();
}
我不知道如何编写logcat文本文件。
答案 0 :(得分:0)
Android应用程序将正在运行的应用程序的日志存储在文件中。您可以使用以下步骤检索日志: