Android 获取内置储存卡/外置储存卡(SD CARD)路径的方法

 
  
/**
 * 内置储存卡路径的获取
 */
//路径一般为: /data/data/包名/files
String absolutePath = getFilesDir().getAbsolutePath();
Log.e("ly","getFilesDir--> "+absolutePath);

//路径一般为: /data/data/包名/cache
String absolutePath1 = getCacheDir().getAbsolutePath();
Log.e("ly","getCacheDir--> "+absolutePath1);

//路径一般为: /data
String absolutePath2 = Environment.getDataDirectory().getAbsolutePath();
Log.e("ly","getDataDirectory--> "+absolutePath2);

/**
 * 外置储存卡路径的获取
 */
//路径一般为:   外置储存卡路径(机型有关)/Android/data/包名/files
String absolutePath3 = getExternalFilesDir(null).getAbsolutePath();
Log.e("ly","getExternalFilesDir--> "+absolutePath3);

//路径一般为:   外置储存卡路径(机型有关)/Android/data/包名/cacches
String absolutePath4 = getExternalCacheDir().getAbsolutePath();
Log.e("ly","getExternalCacheDir--> "+absolutePath4);

//路径一般为:   外置储存卡路径(机型有关)
String absolutePath5 = Environment.getExternalStorageDirectory().getAbsolutePath();
Log.e("ly","getExternalStorageDirectory--> "+absolutePath5);

//路径一般为:  储存卡路径(机型有关)/Movies
String absolutePath6 = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES).getAbsolutePath();
Log.e("ly","getExternalStoragePublicDirectory--> "+absolutePath6);
 
  
以下是运行结果截图,可与上述代码一一对应:
1 华为手机
 
  
 
  
2 联想手机
 
 

你可能感兴趣的:(点滴积累)