Ich möchte meine Datenbank in Datei exportieren. Hier ist mein Code.Datenbank kann nicht von Android-Telefon exportiert werden
public static void backupDatabase(Context mContext) throws IOException {
//Open your local db as the input stream
String DB_PATH=null;
if(android.os.Build.VERSION.SDK_INT >= 17) {
DB_PATH = mContext.getApplicationInfo().dataDir + "/databases/";
} else {
DB_PATH = "/data/data/" + mContext.getPackageName() + "/databases/";
}
DB_PATH=DB_PATH+"SamsungLightingApp.db";
File dbFile = new File(DB_PATH);
FileInputStream fis = new FileInputStream(dbFile);
String outFileName = Environment.getExternalStorageDirectory() + "/MY DB.db";
//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();
}
Wenn wir Fileinputstream öffnen wird es Fehler aus, dass die Datei ist nicht vorhanden. Immer bekomme ich
FileNotFoundException
.
Ich habe das schon gemacht, aber kein Glück – Godwin