这里是包名为"com.study.b8a3"
Context 和 Environment的方法可以得到的路径如下
Context的方法
getDatabasePath(): > /data/user/0/com.study.b8a3/databases/sample.db
getCacheDir(): > /data/user/0/com.study.b8a3/cache
getFilesDir():> /data/user/0/com.study.b8a3/files
getDir("zhao"):> /data/user/0/com.study.b8a3/app_webview/Web Data
getPackageCodePath():> /data/app/com.study.b8a3-1/base.apk
getPackageResourcePath():> /data/app/com.study.b8a3-1/base.apk
getExternalFilesDir():> /storage/emulated/0/Android/data/com.study.b8a3/files
getExternalFilesDirs():> /storage/emulated/0/Android/data/com.study.b8a3/files
getExternalCacheDir():> /storage/emulated/0/Android/data/com.study.b8a3/cache
getExternalCacheDirs(): >/storage/emulated/0/Android/data/com.study.b8a3/cache
getObbDir(): > /storage/emulated/0/Android/obb/com.study.b8a3
getObbDirs(): > /storage/emulated/0/Android/obb/com.study.b8a3
Environment的方法
getExternalStorageState(): > mounted
getExternalStorageDirectory(): > /storage/emulated/0
getDownloadCacheDirectory(): > /cache
getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC):
/storage/emulated/0/Music
getRootDirectory(): > /system
下面是生成的代码, 包名是 com.study.b8a3
Log.e(TAG, "getDatabasePath():>" + context.getDatabasePath("sample.db"));
Log.e(TAG, "getCacheDir():>" + context.getCacheDir());
Log.e(TAG, "getFilesDir():>" + context.getFilesDir());
String[] strings = context.fileList();
for (String path : strings) {//为空
Log.e(TAG, "fileList():>" + path);
}
Log.e(TAG, "getDir(\"zhao\"):>" + context.getDir("webview", context.MODE_PRIVATE).getAbsolutePath() + "/Web Data");
Log.e(TAG, "getPackageCodePath():>" + context.getPackageCodePath());
Log.e(TAG, "getPackageResourcePath():" + context.getPackageResourcePath());
Log.e(TAG, "getExternalFilesDir():" + context.getExternalFilesDir(null));
File[] paths = context.getExternalFilesDirs(null);
for (File path : paths) {
Log.e(TAG, "getExternalFilesDirs():---" + path.getPath());
}
Log.e(TAG, "getExternalCacheDir():" + context.getExternalCacheDir());
paths = context.getExternalCacheDirs();
for (File path : paths) {
Log.e(TAG, "getExternalCacheDirs():---" + path.getPath());
}
Log.e(TAG, "getObbDir():" + context.getObbDir());
paths = context.getObbDirs();
for (File path : paths) {
Log.e(TAG, "getObbDirs():---" + path.getPath());
}
Log.e(TAG, "Environment.getExternalStorageState():" + Environment.getExternalStorageState());
Log.e(TAG, "Environment.getExternalStorageDirectory():" + Environment.getExternalStorageDirectory());
Log.e(TAG, "Environment.getDownloadCacheDirectory():" + Environment.getDownloadCacheDirectory());
Log.e(TAG, "Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC):" + Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC));
Log.e(TAG, "Environment.getRootDirectory():" + Environment.getRootDirectory());
网友评论