以下為Environment類的主要方法,后面是方法返回的路徑
===================
Environment.getDataDirectory(): /data
Environment.getExternalStorageDirectory(): /storage/emulated/0
Environment.getRootDirectory(): /system
Environment.getDownloadCacheDirectory(): /cache
以下為Context類的方法,注意:調用這些方法會自動生成相關的文件夾,不用刻意調用mkdirs()方法,在這些文件夾下操作文件可以不需要權限
===================
Context.getExternalCacheDir(): /storage/emulated/0/Android/data/com.example.administrator.okhttp/cache
Context.getExternalFilesDir(""): /storage/emulated/0/Android/data/com.example.administrator.okhttp/files
Context.getCacheDir(): /data/data/com.example.administrator.okhttp/cache
Context.getFilesDir(): /data/data/com.example.administrator.okhttp/files
Context.getCodeCacheDir(): /data/data/com.example.administrator.okhttp/code_cache
Context.getCallingPackage(): null
Context.getPackageName(): com.example.administrator.okhttp
Context.getPackageCodePath(): /data/app/com.example.administrator.okhttp-1/base.apk
Context.getPackageResourcePath(): /data/app/com.example.administrator.okhttp-1/base.apk
以下方法返回一個File[] ,數組的元素可能為空,所以注意判空
===================
Context.getExternalMediaDirs(): /storage/emulated/0/Android/media/com.example.administrator.okhttp
Context.getExternalCacheDirs(): /storage/emulated/0/Android/data/com.example.administrator.okhttp/cache