安卓上获取各种文件夹的方法

2016-11-12  本文已影响541人  不是所有牛奶都叫特仑苏

以下为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

上一篇 下一篇

猜你喜欢

热点阅读