本文主要是介绍android.os.SystemProperties和android.os.Environment,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
android.os.SystemProperties介绍
public class SystemProperties{public static String get(String key){}public static String get(String key,String def){}public static int getInt(String key,int def){}public static long getLong(String key,long def){}public static boolean getBoolean(String key,boolean def){}public static void set(String key,String val){}
}
android.os.Environment介绍
if(!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)){Toast.makeText(context,”not found SDCard”,Toast.LENGTH_LONG).show();
}else{
try{File file=new File(Evironment.getExternalStorageDirectory(),”/text.txt”);FileOutputStream fos=new FileOutputStream(file);fos.write(content.getBytes());fos.flush();fos.close();
}catch(Exception e){e.printStackTrace();
}
}
其实Android Environment.getExternalStorageDirectory() 获取的 SD卡和手机本身带的存储 ;这两个存储都是外部储存,真正的内部储存位置是data/data/包名,所以用了这个会出现还是存到了手机自带存储上,而不是SD卡上
主要方法:
getRootDierctory()//获取根目录
getDataDirectory()//获取data目录
getExternalStorageDirectory()//获取sd卡目录
getDownloadCacheDirectory()//获取下载文件的缓存目录
getExternalStorageState()//sdcard的状态有:removed,unmounted,checking,nofs,mounted,mounted_ro,shared,unmountable,bad_removal
这篇关于android.os.SystemProperties和android.os.Environment的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!