2011-09-28 98 views

回答

1

如果您的模擬器正在運行,您可以通過打開DDMS透視圖(Window > Open perspective > DDMS)並打開data/data/your.package.name/databases並將其拉到您的計算機上來訪問它。

如果它不是固定的,則無法從設備獲取它。如果是這樣,您將無法訪問它所在的目錄,因爲它受到保護。您必須將其與根資源管理器複製到您的SD卡上,然後您可以將它與DDMS一起拖到您的計算機上。

+0

不,它不是紮根,我該怎麼辦? :(..btw,數據庫是我自己的應用程序的數據庫... – ahsan

+0

然後,你的運氣我覺得很失敗。應用程序數據是私人的 - 有一個很好的理由。我認爲你沒有機會... – Knickedi

6

如果您的應用程序在模擬器中,您可以使用DDMS並打開/data/data/your.package.name/databases

如果你有你的移動應用程序。這裏是我做什麼將數據庫複製到sdcard root文件夾。

/** The name of the database file */ 
    static final String DATABASE_NAME = "mydatabase.db"; 
    static final String DATABASE_NAME_FULL = "/data/data/com.my.application/databases/" + DATABASE_NAME; 

    public static boolean backUpDataBase(Context context){ 
    boolean result = true; 

    // Source path in the application database folder 
    String appDbPath = DATABASE_NAME_FULL; 

    // Destination Path to the sdcard app folder 
    String sdFolder = Environment.getExternalStorageDirectory().getAbsolutePath() + "/" + DATABASE_NAME; 


    InputStream myInput = null; 
    OutputStream myOutput = null; 
    try { 
     //Open your local db as the input stream 
     myInput = new FileInputStream(appDbPath); 
     //Open the empty db as the output stream 
     myOutput = new FileOutputStream(sdFolder); 

     //transfer bytes from the inputfile to the outputfile 
     byte[] buffer = new byte[1024]; 
     int length; 
     while ((length = myInput.read(buffer))>0){ 
      myOutput.write(buffer, 0, length); 
     } 
    } catch (IOException e) { 
     result = false; 
     e.printStackTrace(); 
    } finally { 
     try { 
      //Close the streams 
      if(myOutput!=null){ 
       myOutput.flush(); 
       myOutput.close(); 
      } 
      if(myInput!=null){ 
       myInput.close(); 
      } 
     } catch (IOException e) { } 
    } 

    return result; 
} 

你需要這個在你的manifest.xml

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 
相關問題