1
我使用此代碼,它只保留到輸出文件行並引發異常。任何人都可以看到這條線可能是什麼問題?複製/備份數據庫到SD卡Android
try{
Log.e("Trying","try");
// Local database
InputStream input = new FileInputStream("/data/data/package/databases/database");
Log.e("Input","in");
// create directory for backup
// Path to the external backup
OutputStream output = new FileOutputStream("/sdcard/android/package/databases/mydatabase.db");
Log.e("Output","out");
// transfer bytes from the Input File to the Output File
byte[] buffer = new byte[1024];
Log.e("Buffer","Buff");
int length;
while ((length = input.read(buffer))>0) {
output.write(buffer, 0, length);
}
Log.e("After While","try");
output.flush();
output.close();
input.close();
} catch (IOException e) {
throw new Error("Copying Failed");
}
你可以請把THT異常堆棧跟蹤 –
你在哪裏捕獲異常,你應該做'e.printSatckTrace()'然後將該日誌輸出添加到您的答案中。這樣我們可以看到實際拋出的錯誤。 – Jakar
另外,無論何時您參考Eduardo,您都應該使用Environment:'Environment.getExternalStorageDirectory()'。然後在爲SD卡返回的文件上調用'getAbsolutePath()'。 – Jakar