应用程序个人文件夹路径在哪里 [英] Where is the app Personal Folder path

查看:26
本文介绍了应用程序个人文件夹路径在哪里的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个 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 管理器尝试打开数据库时,我找不到文件夹 /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->从 Devices 列中选择一个模拟器->文件资源管理器.我建议你创建一个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中,有两个文件夹:personal/internal文件夹和public/external文件夹,这里是官方文档.

In android, there are two folder: personal/internal folder and public/external folder, here is official document.

个人/内部文件夹路径:

Personal/Internal Folder path:

/data/data/包名/数据库:Sqlite

/data/data/package name/databases: Sqlite

/data/data/包名/文件:API:getFilesDir()

/data/data/package name/files: Api:getFilesDir()

/data/data/package name/cache: API:getCacheDir()

/data/data/package name/cache: Api:getCacheDir()

/storage/sdcard/Android/data/package name/files: API:getExternalFilesDir()

/storage/sdcard/Android/data/package name/files: Api:getExternalFilesDir()

/storage/sdcard/Android/data/package name/cache: API:getExternalCacheDir()

/storage/sdcard/Android/data/package name/cache: Api:getExternalCacheDir()

公共/外部文件夹路径:

Public/External Folder path:

  • In /storage/sdcard folder, only Android 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"/> 或两者.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆