導航:首頁 > 操作系統 > android資料庫的路徑設置

android資料庫的路徑設置

發布時間:2023-03-09 09:30:54

android怎麼使用外部的資料庫文件

先簡單說下步驟:

將格式為.db的資料庫文件放到android項目assets目錄中;
在程序必要的時候,將其「拷貝」(文件讀取)到Android 程序默認的資料庫存儲目錄中,一般路徑為「/data/data/項目包名/databases/「;
自定義SQLiteOpenHelper類,創建一個名字跟步驟1中.db名稱一樣的資料庫;
按照平常邏輯,增刪改查資料庫。

Ⅱ 在Android應用程序中創建的資料庫,儲存在手機的哪個文件夾

  1. 打開手機【文件管理】

  2. 選擇【手機】---SD卡----Android---data

  3. 查看你需要的文件

Ⅲ android 資料庫文件存在哪裡

默認路徑是/data/data/然後是你創建的包名,然後就找到你創建的資料庫名字了

Ⅳ 安卓手機開發,創建SQlite資料庫後,默認路徑是存儲在哪

android的資料庫是保存在虛擬AVD設備中的吧。(就是你給AVD分配的那塊空間里) 你用adb連接上AVD設備,在從相應的路徑里取出資料庫文件。

Ⅳ Android 請問如何更改android 資料庫的存儲路徑

These files will be ones that get deleted first when the device runs low on storage. There is no guarantee when these files will be deleted.
但是,最好不要依賴系統來管理,應該自己設定一個最大容量,當超出這個值時自己刪除。

Context.getFilesDir(),Context.openFileOutput(String, int),Context.getFileStreamPath(String),Context.getDir(String, int)
/data/data/files
Android支持在SD卡上的應用私有目錄,在Froyo版本後,通過getExternalFilesDir()可以獲得具體路徑。該路徑依賴與應用的包名,如果你包為hello.file那麼SD開上的應用私有目錄為\mnt\sdcard\Android\data\hello.file\files\.
在使用SD卡目錄時,需注意SD卡是否掛載,可通過Environment.getExternalStorageState()方法進行判斷,如果返回值為Envirnment.MEDIA_MOUNTED表示SD卡處於掛載狀態,可以放心使用。

getExternalCacheDir()和getCacheDir()比較
共同點:
files will be deleted when the application is uninstalled
不同點:
1、The platform does not monitor the space available in external storage, and thus will not automatically delete these files. Note that you should be managing the maximum space you will use for these anyway, just like with getCacheDir().
2、External files are not always available: they will disappear if the user mounts the external storage on a computer or removes it. See the APIs on Environment for information in the storage state.
3、There is no security enforced with these files. All applications can read and write files placed here.

Ⅵ android Room資料庫框架 怎麼自定義 sqlite db文件路徑

要在Android系統中操作SQLite資料庫,是通過Android的核心類SQLiteDatabase類來實現的,通常情況下為了資料庫升級的需要以及使用方便,會選擇繼承SQLiteOpenHelper抽像類,但是SQLiteOpenHelper會將資料庫文件創建在一個固定的目錄(內存的/data/data/<package name/databases>目錄中),如果想使用已經存在的資料庫文件也就是說資料庫會和程序一起發布,就得通過使用SQLiteDabase的靜態方法OpenOrCreateDatabase()方法來得到SQLiteDabase對象,下面是一個具體操作類:
package net.my.;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import net.my.jokebook.R;
import android.app.Activity;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
public class DBHelper {
//得到SD卡路徑
private final String DATABASE_PATH = android.os.Environment
.getExternalStorageDirectory().getAbsolutePath()
+ "/joke";
private final Activity activity;
//資料庫名
private final String DATABASE_FILENAME;
public DBHelper(Context context) {
// TODO Auto-generated constructor stub
//這里直接給資料庫名
DATABASE_FILENAME = "jokebook.db3";
activity = (Activity)context;
}
//得到操作資料庫的對象
public SQLiteDatabase openDatabase()
{
try
{
boolean b = false;
//得到資料庫的完整路徑名
String databaseFilename = DATABASE_PATH + "/" + DATABASE_FILENAME;
//將資料庫文件從資源文件放到合適地方(資源文件也就是資料庫文件放在項目的res下的raw目錄中)
//將資料庫文件復制到SD卡中 File dir = new File(DATABASE_PATH);
if (!dir.exists())
b = dir.mkdir();
//判斷是否存在該文件
if (!(new File(databaseFilename)).exists())
{
//不存在得到資料庫輸入流對象
InputStream is = activity.getResources().openRawResource(
R.raw.jokebook);
//創建輸出流
FileOutputStream fos = new FileOutputStream(databaseFilename);
//將數據輸出
byte[] buffer = new byte[8192];
int count = 0;
while ((count = is.read(buffer)) > 0)
{
fos.write(buffer, 0, count);
}
//關閉資源
fos.close();
is.close();
}
//得到SQLDatabase對象
SQLiteDatabase database = SQLiteDatabase.openOrCreateDatabase(
databaseFilename, null);
return database;
}
catch (Exception e)
{
System.out.println(e.getMessage());
}
return null;
}
}
寫完這個類之後,就能得到SQLiteDatabase對象,就能對資料庫操作了。

閱讀全文

與android資料庫的路徑設置相關的資料

熱點內容
前端如何認證伺服器 瀏覽:554
linux切換db2用戶命令 瀏覽:306
相片如何用電解壓 瀏覽:905
碩士程序員去學校當老師 瀏覽:120
pythonstr提取到字典 瀏覽:818
程序員那麼可愛有人看上陸漓了 瀏覽:876
php正則提取圖片 瀏覽:103
pythonlinuxdjango 瀏覽:562
php中文返回亂碼 瀏覽:89
宿舍裝的電信怎麼加密 瀏覽:745
為什麼壓縮文件解壓後變少了 瀏覽:426
現在安卓充電器普遍是什麼型號 瀏覽:714
9日均線36均線主圖指標源碼 瀏覽:349
程序員阿里文化完整版 瀏覽:98
早間新聞在哪個app上面可以看 瀏覽:954
工作啦app注冊的信息怎麼刪去 瀏覽:378
滾動轉子式製冷壓縮機 瀏覽:873
美國編程用什麼軟體 瀏覽:571
圖片加密防盜用 瀏覽:616
dbscan演算法python源碼 瀏覽:849