赞
踩
getFilesDir();获取内置存储下文件根目录
getCacheDir();获取内置存储下的缓存目录
getExternalFilesDir();获取扩展存储根目录 /storage/emulated/0/Android/data/包名/files/
getExternalCacheDir();获取缓存目录,
openFileInput(String name); 打开名为那么的文件返回FileInputStream
openFileOutput(String name,int mode); 打开名为那么的文件返回FileOutputStream
mode常量:
MODE_APPEND 写入内容追加到末尾
MODE_PRIVATE 文件私有的默认模式,覆盖
if(Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)){
//可用
}
private void quabXian(Activity activity) {
String[] USER_PERMISSION = {Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE};
for(int i = 0;i< USER_PERMISSION.length;i++){
int permission = ActivityCompat.checkSelfPermission(activity,USER_PERMISSION[i]);
if(permission!=PackageManager.PERMISSION_GRANTED){
ActivityCompat.requestPermissions(activity,new String[]{USER_PERMISSION[i]},i);
}
}
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。