我遇到了導出數據庫的內部路徑問題。日誌說這是錯誤的路徑。Android路徑內部存儲
File sd = Environment.getExternalStorageDirectory();
File data = Environment.getDataDirectory();
FileChannel source=null;
FileChannel destination=null;
String cartella = (getString(R.string.app_name));
String currentDBPath = "/data/"+getPackageName()+"/cartella/"+"Backup.db";
String backupDBPath = "/cartella/Backup.db";
File currentDB = new File(data, currentDBPath);
File backupDB = new File(sd, backupDBPath);
try {
source = new FileInputStream(currentDB).getChannel();
destination = new FileOutputStream(backupDB).getChannel();
destination.transferFrom(source, 0, source.size());
source.close();
destination.close();
Toast.makeText(this, "DB Exported!", Toast.LENGTH_LONG).show();
} catch(IOException e) {
e.printStackTrace();
Toast toast = Toast.makeText(getApplicationContext(),(R.string.Toast_export_errore), Toast.LENGTH_SHORT);
toast.show();
登錄
01-20 08:55:14.757: W/System.err(1383): java.io.FileNotFoundException: /data/data/info.androidhive.slidingmenu/cartella/Backup.db: open failed: ENOENT (No such file or directory)
八月1日至20日:55:14.787:W/System.err的(1383):在libcore.io.IoBridge.open(IoBridge.java:409) 01 - 08:55:14.827:W/System.err(1383):在java.io.FileInputStream。(FileInputStream.java:78) 01-20 08:55:14.827:W/System.err(1383): at main.Impostazioni.Esporta(Impostazioni.java:334) 01-20 08:55:14.827:W/System.err(1383):at java.lang.reflect.Method.invokeNative(Native Method) 01-20 08:55:14.827:W/System.err(1383):在java.lang.reflect.Met hod.invoke(Method.java:525) 01-20 08:55:14.827:W/System.err(1383):at android.view.View $ 1.onClick(View.java:3628) 01-20 08 :55:14.857:W/System.err(1383):at android.view.View.performClick(View.java:4240) 01-20 08:55:14.857:W/System.err(1383):at android .view.View $ PerformClick.run(View.java:17721) 01-20 08:55:14.877:W/System.err(1383):at android.os.Handler.handleCallback(Handler.java:730) 01-20 08:55:14.877:W/System.err(1383):at android.os.Handler.dispatchMessage(Handler.java:92) 01-20 08:55:14.887:W/System.err(1383 ):at android.os.Looper.loop(Looper.java:137) 01-20 08:55:14.898:W/System.err(1383):at android.app.ActivityThread.main(ActivityThread.java:5103 ) 01-20 08:55:14.927:W/System.err(1383):at java.lang.reflect.M ethod.invokeNative(Native Method) 01-20 08:55:14.927:W/System.err(1383):at java.lang.reflect.Method.invoke(Method.java:525) 01-20 08:55 :14.957:W/System.err(1383):at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:737) 01-20 08:55:14.957:W/System.err(1383) ):at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 01-20 08:55:14.987:W/System.err(1383):at dalvik.system.NativeStart.main(Native法) 八月1日至20日:55:14.987:W/System.err的(1383):libcore.io.ErrnoException:致打開失敗:ENOENT(沒有這樣的文件或目錄)
請張貼您的日誌 –