getExternalFilesDir和getExternalStorageDirectory之间的差异()差异、getExternalFilesDir、getExternalStorageDirec

2023-09-12 07:22:35 作者:安慰良人

据我所知,ExternalFiles是要在API 8使用,并getExternalStorageDirectory是7和向下。不过我是用的有点迷糊。比如我要检查存在和previously你会使用类似的文件夹:

 文件ChildFolder =新的文件(Environment.getExternalStorageDirectory()+/ ParentFolder /儿童);
 

不过每个实例我看到说,使用getExternalFilesDir(空),File.ext。由于我上面的API 8我想用这个方法,但我怎么只检查一个文件夹?我会检查一个文件的存在,在另一点,但现在只是想看看,如果文件夹存在?

TIA JB

解决方案

  getExternalFilesDir()
 

它返回的路径为文件文件夹中的的Andr​​oid /数据/数据​​/ your_package / 在你的SD卡。它是用于存储您的应用程序(从网络或高速缓存下载的文件如图像)的任何所需的文件。一旦应用被卸载后,存储在该文件夹中的所有数据都消失了。

  getExternalStorageDirectory()
 
2020 看雪SDC议题回顾 LightSpy Mobile间谍软件的狩猎和剖析

它返回的根路径到你的SD卡(如 MNT / SD卡/ )。如果您保存数据这条道路上和卸载应用程序,数据也不会丢失。

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");

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??

TIA JB

解决方案

getExternalFilesDir()

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()

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.