簡體   English   中英

如何使用Android Studio從模擬器的data文件夾訪問SQLite數據庫?

[英]How can I access the SQLite database from the data folder in the emulator using Android Studio?

我正在嘗試從Android Studio中的Android設備管理器中的數據文件夾訪問SQLite數據庫。 我正在使用Nexus_4_API_24模擬器。 當我嘗試打開數據文件夾時,沒有任何顯示,好像它是空的。 我搜索了地獄,但仍然找不到問題的答案。

謝謝

您可以將數據庫復制到您知道可以訪問的位置。 如果只有內存可用,則您的應用程序可以訪問文件夾/data/data/yourapp/yourdb.sql,因此,除非您的文件資源管理器具有訪問此文件夾的特定權限,否則最好的方法是將其復制到其他位置。 我知道您可以使用此文件復制文件,但從未使用db對其進行測試,

     public static void copyFile(String src, String dst) throws IOException
{
    FileChannel inChannel = new FileInputStream(src).getChannel();
    FileChannel outChannel = new FileOutputStream(dst).getChannel();
    try
    {
        inChannel.transferTo(0, inChannel.size(), outChannel);
    }
    finally
    {
        if (inChannel != null)
            inChannel.close();
        if (outChannel != null)
            outChannel.close();
    }
}

隨着src和dst是這樣的:

      src=mContext.getFilesDir().getAbsolutePath()+"/yourdbname.sql";
      dst=mContext.getExternalFilesDir(Environment.DIRECTORY_DOCUMENTS).getAbsolutePath()+"/yourdbname.sql";

然后在文件資源管理器jsut中轉到sdcard / Android / yourapp / Documents / yourdb.sql

希望我回答了這個問題,希望對您有幫助

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM