关于Android文件路径的记录
// 测试文件路径
// 联想测试 filePath = "/data/data/et.tsingtaopad.uploadapk/files/headImg/picname.png"
// 小米测试 filePath = "/data/user/0/et.tsingtaopad.uploadapk/files/headImg/picname.png"
String filePath = getFilesDir().getAbsolutePath() + File.separator + "headImg" + File.separator + "picname.png";
// 联想测试 filePath1 = "/data"
// 小米测试 filePath1 = "/data"
File filePath1 = Environment.getDataDirectory();
// 联想测试 filePath2 = "/cache"
// 小米测试 filePath2 = "/cache"
File filePath2 = Environment.getDownloadCacheDirectory() ;
// 联想测试 filePath3 = "/storage/emulated/0"
// 小米测试 filePath3 = "/storage/emulated/0"
File filePath3 = getExternalStorageDirectory();// = /mnt/sdcard
// 联想测试 filePath4 = "/storage/emulated/0/test"
// 小米测试 filePath4 = "/storage/emulated/0/test"
File filePath4 = Environment.getExternalStoragePublicDirectory("test");//= /mnt/sdcard/test
// 联想测试 filePath5 = "/system"
// 小米测试 filePath5 = "/system"
File filePath5 = Environment.getRootDirectory();
// 联想测试 filePath6 = "/data/app/et.tsingtaopad.uploadapk-1.apk"
// 小米测试 filePath6 = "/data/app/et.tsingtaopad.uploadapk-1/base.apk"
String filePath6 = getPackageCodePath() ; // = /data/app/com.my.app-1.apk
// 联想测试 filePath7 = "/data/app/et.tsingtaopad.uploadapk-1.apk"
// 小米测试 filePath7 = "/data/app/et.tsingtaopad.uploadapk-1/base.apk"
String filePath7 = getPackageResourcePath(); // = /data/app/com.my.app-1.apk
// 联想测试 filePath8 = "/data/data/et.tsingtaopad.uploadapk/cache"
// 小米测试 filePath8 = "/data/user/0/et.tsingtaopad.uploadapk/cache"
File filePath8 = getCacheDir() ;// = /data/data/com.my.app/cache
// 联想测试 filePath9 = "/data/data/et.tsingtaopad.uploadapk/databases/test"
// 小米测试 filePath9 = "/data/user/0/et.tsingtaopad.uploadapk/databases/test"
File filePath9 = getDatabasePath("test") ; // = /data/data/com.my.app/databases/test
// 联想测试 filePath10 = "/data/data/et.tsingtaopad.uploadapk/app_test"
// 小米测试 filePath10 = "/data/user/0/et.tsingtaopad.uploadapk/app_test"
File filePath10 = getDir("test", Context.MODE_PRIVATE); // = /data/data/com.my.app/app_test
// 联想测试 filePath11 = "/storage/emulated/0/Android/data/et.tsingtaopad.uploadapk/cache"
// 小米测试 filePath11 = "/storage/emulated/0/Android/data/et.tsingtaopad.uploadapk/cache"
File filePath11 = getExternalCacheDir(); // = /mnt/sdcard/Android/data/com.my.app/cache
// 联想测试 filePath12 = "/storage/emulated/0/Android/data/et.tsingtaopad.uploadapk/files/test"
// 小米测试 filePath12 = "/storage/emulated/0/Android/data/et.tsingtaopad.uploadapk/files/test"
File filePath12 = getExternalFilesDir("test") ;// = /mnt/sdcard/Android/data/com.my.app/files/test
// 联想测试 filePath13 = "/storage/emulated/0/Android/data/et.tsingtaopad.uploadapk/files"
// 小米测试 filePath13 = "/storage/emulated/0/Android/data/et.tsingtaopad.uploadapk/files"
File filePath13 = getExternalFilesDir(null) ; //= /mnt/sdcard/Android/data/com.my.app/files
// 联想测试 filePath14 = "/data/data/et.tsingtaopad.uploadapk/files"
// 小米测试 filePath14 = "/data/user/0/et.tsingtaopad.uploadapk/files"
File filePath14 = getFilesDir(); // = /data/data/com.my.app/files
// 联想测试 filePath15 = "/storage/emulated/0"
// 小米测试 filePath15 = "/storage/emulated/0"
String filePath15 = Environment.getExternalStorageDirectory().getPath();
// 联想测试 filePath16 = "/storage/emulated/0/Android/data/et.tsingtaopad.uploadapk/cache/file16"
// 小米测试 filePath16 = "/storage/emulated/0/Android/data/et.tsingtaopad.uploadapk/cache/file16"
File filePath16 = getDiskCacheDir(this,"file16");
// 联想测试 filePath17 = "/storage/emulated/0/Android/data/et.tsingtaopad.uploadapk/cache"
// 小米测试 filePath17 = "/storage/emulated/0/Android/data/et.tsingtaopad.uploadapk/cache"
String filePath17 = getDiskCacheDir(this);
//----------------------------------------------------------------------
// 获取scared的文件夹路径
通过Context.getExternalFilesDir()方法可以获取到 SDCard/Android/data/你的应用的包名/files/ 目录,一般放一些长时间保存的数据
通过Context.getExternalCacheDir()方法可以获取到 SDCard/Android/data/你的应用包名/cache/目录,一般存放临时缓存数据
// 获取手机存储空间的文件夹路径 /data/data/et.tsingtaopad/files/photo/
String path = getFilesDir().getAbsolutePath() + File.separator + "photo"+ File.separator;
getCacheDir()方法用于获取/data/data/<application package>/cache目录
getFilesDir()方法用于获取/data/data/<application package>/files目录
//--------------------------------------------------------------------
/**
* 获取缓存文件夹
* 通常都会存放在 /sdcard/Android/data/<application package>/cache 这个路径下面,
* 但同时我们又需要考虑如果这个手机没有SD卡,或者SD正好被移除了的情况,因此专门写一个方法来获取缓存地址
*
*/
public File getDiskCacheDir(Context context, String uniqueName) { // 上下文 文件夹名称
String cachePath;
if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())
|| !Environment.isExternalStorageRemovable()) {
//缓存在sdcard上 SDCard/Android/data/你的应用包名/cache/目录
cachePath = context.getExternalCacheDir().getPath();
} else {
// 缓存在手机存储空间上 /data/data/<application package>/cache目录
cachePath = context.getCacheDir().getPath();
}
return new File(cachePath + File.separator + uniqueName);
}
// 获取缓存文件夹路径
public String getDiskCacheDir(Context context) {
String cachePath = null;
if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())
|| !Environment.isExternalStorageRemovable()) {
//SDCard/Android/data/你的应用包名/cache/目录
cachePath = context.getExternalCacheDir().getPath();
} else {
///data/data/<application package>/cache目录
cachePath = context.getCacheDir().getPath();
}
return cachePath;
}