Android local storage path

1. Built-in storage path of mobile application

  • getFilesDir().getAbsolutePath()
  • getFilesDir().getPath()
  • getCacheDir().getAbsolutePath()
  • getCacheDir().getPath()

Experiment code:

String savePath5 = getFilesDir().getAbsolutePath();
String savePath6 = getFilesDir().getPath();

String savePath7 = getCacheDir().getAbsolutePath();
String savePath8 = getCacheDir().getPath();


Log.d(TAG,"save path5 --------->"+savePath5);
Log.d(TAG,"save path6 --------->"+savePath6);

Log.d(TAG,"save path7 --------->"+savePath7);
Log.d(TAG,"save path8 --------->"+savePath8);

Print result:

tag:save path5 --------->/data/user/0/fxjzzyo.com.ffmpegtest/files
tag:save path6 --------->/data/user/0/fxjzzyo.com.ffmpegtest/files

tag: save path7 --------->/data/user/0/fxjzzyo.com.ffmpegtest/cache
tag: save path8 --------->/data/user/0/fxjzzyo.com.ffmpegtest/cache

in conclusion:

  • getFilesDir() returns the folder /data/user/0/package name/files, which is related to the existence of the application. When the application is uninstalled, the contents inside are also deleted.
  • In the same way, getCacheDir() returns the folder /data/user/0/package name/cache, which is related to the existence of the application. When the application is uninstalled, the contents inside are also deleted.
  • In addition, the results of my experiment here getAbsolutePath() and getPath() return the same path, so you don’t have to worry about it when you use it. I plan to use the absolute path getAbsolutePath() in the future.

2. Storage path of external sd card of mobile phone

There are two ways to obtain, one is to obtain the root directory of the SD card, and the other is to obtain the directory of the SD card related to the application.

2.1 Get the root directory path of the sd card

  • Environment.getExternalStorageDirectory().getAbsolutePath()

Experiment code:

String savePath9 = Environment.getExternalStorageDirectory().getAbsolutePath();
String savePath10 = Environment.getExternalStorageDirectory().getPath();

Log.d(TAG,"save path9 --------->"+savePath9);
Log.d(TAG,"save path10 --------->"+savePath10);

Print result:

tag: save path9 --------->/storage/emulated/0
tag: save path10 --------->/storage/emulated/0

in conclusion:

  • Environment.getExternalStorageDirectory() gets the root directory folder of the sd card, which has nothing to do with the application. Even if the application is uninstalled, the contents in it still exist.

2.2 Get the SD card directory path related to the application

  • getExternalFilesDir (null) .getAbsolutePath ()

Experiment code:

String savePath = getExternalFilesDir(null).getAbsolutePath();
String savePath2 = getExternalFilesDir(null).getPath();
String savePath3 = getExternalCacheDir().getAbsolutePath();
String savePath4 = getExternalCacheDir().getPath();

Log.d(TAG,"save path --------->"+savePath);
Log.d(TAG,"save path2 --------->"+savePath2);
Log.d(TAG,"save path3 --------->"+savePath3);
Log.d(TAG,"save path4 --------->"+savePath4);

Print result:

tag: save path --------->/storage/emulated/0/Android/data/fxjzzyo.com.ffmpegtest/files
tag: save path2 --------->/storage/emulated/0/Android/data/fxjzzyo.com.ffmpegtest/files
tag: save path3 --------->/storage/emulated/0/Android/data/fxjzzyo.com.ffmpegtest/cache
tag: save path4 --------->/storage/emulated/0/Android/data/fxjzzyo.com.ffmpegtest/cache

in conclusion:

  • getExternalFilesDir(null) gets the folder /storage/emulated/0/Android/data/package name/files, which is related to the application. After uninstalling the application, the content inside is gone.
  • In the same way, getExternalCacheDir() gets the folder /storage/emulated/0/Android/data/package name/cache, which is related to the application. After uninstalling the application, the content inside is gone.

Reference article:
https://blog.csdn.net/xiao_sier/article/details/78667149

Guess you like

Origin blog.csdn.net/fxjzzyo/article/details/84787968