应用程序的个人文件夹路径在哪里 [英] Where is the app Personal Folder path
问题描述
我正在尝试创建sqlLite数据库.这段代码可以工作并创建数据库,并允许我进行插入和选择.
Im trying to create a sqlLite db. This code works and create the db and allow me do insert and select.
string dbPath = Path.Combine(
System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal),
"ormdemo.db3");
//dbPath = "/storage/emulated/0/DCIM/ormdemo.db3";
var db = new SQLiteConnection(dbPath);
db.CreateTable<Stock>();
现在返回的dbPath是:
Right now the dbPath returned is:
"/data/user/0/MyFirstGPSApp.MyFirstGPSApp/files/ormdemo.db3"
但是当我使用sqlLite Manager尝试打开数据库时,找不到文件夹/data/user
But when I use a sqlLite Manager to try open the db I cant find the folder /data/user
文件夹/data/user
在哪里?
Where is that folder /data/user
?
sqlLite可以选择打开"APP"数据库,但是当尝试选择MyFirstGPSApp
时说需要一个根设备.
The sqlLite have the option to open "APP" databases, but when try to select MyFirstGPSApp
say need a root device.
sqlLite的起始文件夹为/storage/emulated/0
,并具有子文件夹/DCIM
The starting folder for sqlLite is /storage/emulated/0
and have a sub folder /DCIM
所以我尝试使用一个我可以看到的文件夹,例如/storage/emulated/0/DCIM/ormdemo.db3
,但随后new SQLiteConnection(dbPath)
给我这个错误.
So I try to use a folder I can see ... like /storage/emulated/0/DCIM/ormdemo.db3
but then the new SQLiteConnection(dbPath)
give me this error.
SQLite.SQLiteException:无法打开数据库文件:/storage/emulated/0/DCIM/ormdemo.db3(CannotOpen)
SQLite.SQLiteException: Could not open database file: /storage/emulated/0/DCIM/ormdemo.db3 (CannotOpen)
在/DCIM
文件夹中写入是否需要特殊的权限?
Do I need special permision to write in /DCIM
folder?
推荐答案
好的,您的帖子中有三个问题.在回答您的问题之前,我认为需要一些图片.
Ok, there are three questions in your post. Before answer your questions, I think some pictures are necessary.
P1:
P2:
就像@Yogesh Paliyal所说,您需要File Explorer
才能看到它.如果您也想看到它,并且不想让您的设备成为root用户,请关注我:Visual Studio->Tools->Android->Android Device Monitor->select one simulator from Devices column->File Explorer
.我建议您创建一个Api低于21的模拟器,因为更高的模拟器也看不到该文件.我正在使用19来查看文件.
Like @Yogesh Paliyal has said, you need File Explorer
to see it. If you also want to see it and you don't want to root you device, please follow me: Visual Studio->Tools->Android->Android Device Monitor->select one simulator from Devices column->File Explorer
. I suggest you create a simulator which Api is below 21, because the higher also can't see the file. I am using 19 to see the files.
我认为您应该阅读此首先.
And I think you should read this firstly.
好,让我们看看您的问题:
Ok, let's see your questions:
应用的个人文件夹"路径在哪里?
Where is the app Personal Folder path?
在android中,有两个文件夹:个人/内部文件夹和公共/外部文件夹,
In android, there are two folder: personal/internal folder and public/external folder, here is official document.
个人/内部文件夹路径:
Personal/Internal Folder path:
-
/数据/数据/包名称/shared_prefs: SharedPreferences
/data/data/package name/databases: Sqlite
/数据/数据/包名称/文件: Api: getFilesDir()
/data/data/package name/files: Api:getFilesDir()
/数据/数据/包名称/缓存: Api: getCacheDir()
/data/data/package name/cache: Api:getCacheDir()
/storage/sdcard/Android/data/程序包名称/文件:
/storage/sdcard/Android/data/package name/files: Api:getExternalFilesDir()
/storage/sdcard/Android/data/程序包名称/缓存:
/storage/sdcard/Android/data/package name/cache: Api:getExternalCacheDir()
公共/外部文件夹路径:
Public/External Folder path:
- 在
/storage/sdcard
文件夹中,只有Android
文件夹是个人/内部文件夹,因此/storage/sdcard/DCIM
,/storage/sdcard/Music
等,它们都是公共/外部文件夹:
- In
/storage/sdcard
folder, onlyAndroid
folder is personal/internal folder,so/storage/sdcard/DCIM
,/storage/sdcard/Music
,etc, all of them are public/external folder: Api:Environment.getExternalStoragePublicDirectory(String type)
该文件夹/data/user在哪里?
Where is that folder /data/user?
在P1中,您可以看到->/data/data/
在/data/user/0
的后面,因此文件夹/data/user/0/MyFirstGPSApp.MyFirstGPSApp/files/ormdemo.db3
实际上是/data/data/MyFirstGPSApp.MyFirstGPSApp/files/ormdemo.db3
.
From P1, you can see the ->/data/data/
is behind of /data/user/0
, so the folder /data/user/0/MyFirstGPSApp.MyFirstGPSApp/files/ormdemo.db3
is /data/data/MyFirstGPSApp.MyFirstGPSApp/files/ormdemo.db3
actually.
我需要特殊的权限才能写入/DCIM文件夹吗?
Do I need special permision to write in /DCIM folder?
个人/内部文件夹不需要权限,公共/外部文件夹需要权限.
Personal/Internal folder doesn't need permission, public/external folder need permission.
在/storage/sdcard
文件夹中,只有Android
文件夹是个人/内部文件夹,因此您需要权限:<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
或<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
或二者兼有.
In /storage/sdcard
folder, only Android
folder is personal/internal folder, so you need permission:<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
or <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
or both.
这篇关于应用程序的个人文件夹路径在哪里的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!