2011-09-28 102 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" /> 
相关问题