Androidローカルストレージパス

1.モバイルアプリケーションの組み込みストレージパス

  • getFilesDir()。getAbsolutePath()
  • getFilesDir()。getPath()
  • getCacheDir()。getAbsolutePath()
  • getCacheDir()。getPath()

実験コード:

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

結果の印刷:

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

結論として:

  • getFilesDir()は、アプリケーションの存在に関連するフォルダー/ data / user / 0 / package name / filesを返します。アプリケーションがアンインストールされると、内部のコンテンツも削除されます。
  • 同様に、getCacheDir()は、アプリケーションの存在に関連するフォルダー/ data / user / 0 / package name / cacheを返します。アプリケーションがアンインストールされると、内部のコンテンツも削除されます。
  • また、ここでの実験結果getAbsolutePath()とgetPath()は同じパスを返すので、絡める必要はありません。将来的には絶対パスgetAbsolutePath()を使用する予定です。

2.携帯電話の外部SDカードのストレージパス

取得する方法は2つあります。1つはSDカードのルートディレクトリを取得する方法、もう1つはアプリケーションに関連するSDカードのディレクトリを取得する方法です。

2.1SDカードのルートディレクトリパスを取得します

  • Environment.getExternalStorageDirectory()。getAbsolutePath()

実験コード:

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

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

結果の印刷:

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

結論として:

  • Environment.getExternalStorageDirectory()は、SDカードのルートディレクトリフォルダを取得します。これは、アプリケーションとは関係ありません。アプリケーションがアンインストールされても、その中身は存在します。

2.2アプリケーションに関連するSDカードのディレクトリパスを取得する

  • getExternalFilesDir(null).getAbsolutePath()

実験コード:

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

結果の印刷:

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

結論として:

  • getExternalFilesDir(null)は、アプリケーションに関連するフォルダー/ storage / emulated / 0 / Android / data / package name / filesを取得します。アプリケーションをアンインストールすると、内部のコンテンツは失われます。
  • 同様に、getExternalCacheDir()は、アプリケーションに関連する/ storage / emulated / 0 / Android / data / package name / cacheフォルダーを取得します。アプリケーションをアンインストールすると、内部のコンテンツは失われます。

参考記事:https
//blog.csdn.net/xiao_sier/article/details/78667149

おすすめ

転載: blog.csdn.net/fxjzzyo/article/details/84787968