getExternalFilesDir 和 getExternalStorageDirectory() 的区别 [英] Difference between getExternalFilesDir and getExternalStorageDirectory()

查看:30
本文介绍了getExternalFilesDir 和 getExternalStorageDirectory() 的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道 ExternalFiles 将用于 API 8 及更高版本,而 getExternalStorageDirectory 用于 API 7 及更低版本.但是我在使用之间有点困惑.例如,我想检查一个文件夹是否存在,之前您会使用以下内容:

I understand that ExternalFiles is to be used on API 8 and up and getExternalStorageDirectory is for 7 and down. However I am a little confused between the use. For example I wanted to check that a folder that exists and previously you would use something like:

File ChildFolder = new File(Environment.getExternalStorageDirectory() + "/ParentFolder/Child");

但是,我看到的每个示例都说要使用 getExternalFilesDir (null)、File.ext.由于我高于 API 8,我想使用此方法,但我如何只检查文件夹?我会在另一点检查文件是否存在,但现在只想看看文件夹是否存在??

However every example I see says to use getExternalFilesDir (null), File.ext. Since I am above API 8 I want to use this method but how do I just check for a folder? I will check for a files existence at another point but for now just want to see if the folders exist??

推荐答案

getExternalFilesDir()

它返回 SD 卡上 Android/data/data/your_package/files 文件夹的路径.它用于存储您的应用程序所需的任何文件(例如从网络下载的图像或缓存文件).卸载应用程序后,此文件夹中存储的所有数据也将消失.

It returns the path to files folder inside Android/data/data/your_package/ on your SD card. It is used to store any required files for your app (e.g. images downloaded from web or cache files). Once the app is uninstalled, any data stored in this folder is gone too.

getExternalStorageDirectory()

它返回 SD 卡的根路径(例如 mnt/sdcard/).如果您在此路径上保存数据并卸载该应用程序,则该数据不会丢失.

It returns the root path to your SD card (e.g mnt/sdcard/). If you save data on this path and uninstall the app, that data won't be lost.

这篇关于getExternalFilesDir 和 getExternalStorageDirectory() 的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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