2014-01-06 29 views
0

對不起,我有一個.db sqlite3文件,我想採取的數據,例如它是隻讀的。但是我想知道在何處導入它,同時爲了連接它而採用這個數據文件的路徑?你可以幫我嗎?在android項目中保存只讀* .db文件的位置?

+0

context.getFilesDir – njzk2

+0

對不起,你能更具體嗎? – elgolondrino

+0

資產文件夾如果是預填充的數據庫:http://stackoverflow.com/questions/2409126/android-pre-populated-database – sabadow

回答

0

進口它下面的路徑

"/data/data/ur_package_name/databases/" 
+0

我只知道'DRAG和DROP':)在日食,如何做編程方式?順便說一句,* .db已經創建! – elgolondrino

0

在項目中,我下的項目,稱爲資產的文件夾,我把我的* .db的存在,並加載這樣的數據庫:

private static void copyDatabase(String dbname) throws IOException { 
     InputStream is = mContext.getAssets().open(dbname); 
     String outFileName = DB_PATH + dbname; 
     OutputStream out = new FileOutputStream(outFileName); 
     byte[] buffer = new byte[1024]; 
     int length; 
     while ((length = is.read(buffer)) > 0) { 
      out.write(buffer, 0, length); 
     } 
     is.close(); 
     out.flush(); 
     out.close(); 
    } 
相關問題