android Properties的使用
来源:互联网 发布:测绘数据数据转换工具 编辑:程序博客网 时间:2024/06/04 20:05
Android 下面Properties可用来保存程序的一些配置,其简单用法如下
public class MainActivity extends Activity {Button btnInput=null;Button btnRead=null;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.mylayout);btnInput=(Button)findViewById(id.btnInput);btnInput.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {//首先创建 PropertiesProperties pro=new Properties();pro.put("name", "test");SetProperties(pro);}});btnRead=(Button)findViewById(id.bntRead);btnRead.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {//读取Properties pro=GetProperties();Toast.makeText(MainActivity.this,pro.getProperty("name"), Toast.LENGTH_SHORT).show();}});}/** * 获取Properties * @return */private Properties GetProperties(){Properties pro=new Properties();FileInputStream stream=null;File file=this.getDir("Config", Context.MODE_PRIVATE);try {stream=new FileInputStream(file.getPath()+File.separator+"config");pro.load(stream);} catch (Exception e) {e.printStackTrace();}finally{try {stream.close();} catch (Exception e) {e.printStackTrace();}}return pro;}/** * 设置Properties * @param pro */private void SetProperties(Properties pro){FileOutputStream stream=null;File dir=this.getDir("Config", Context.MODE_PRIVATE);//获得路径为data/data/包名/app_+传入的name 这里为app_configtry {File file=new File(dir,"config");//在上面的路径下创建config文件stream=new FileOutputStream(file);pro.store(stream,"");} catch (Exception e) {e.printStackTrace();}}};
0 0
- android Properties的使用
- Android自定义配置文件(.properties文件)的使用
- 分享:Android -- Properties使用
- Android Properties 使用实例
- 使用JAVA的Properties
- Properties 类的使用
- Properties 类的使用
- log4j.properties的使用
- properties类的使用
- 配置文件properties的使用
- properties文件的使用
- Properties的使用
- 档案文件properties的使用
- Properties的使用
- Properties类的使用
- Properties的使用
- Properties对象的使用
- Properties的使用
- Windows的字符串
- 浙大 pat Basic Level 1018
- Arcgis for Sliverlight 加载百度地图
- 电源主板CPU内存
- 硬盘属于外部存储器
- android Properties的使用
- KVO 的概述与使用
- VS2010提示error TRK0002: Failed to execute command解决方法
- 去除chrome、safari表单元素获取焦点时黄色或蓝色边框
- Proguardgui
- 显卡网卡
- 一些重要的算法
- struts2入门知识3--动态方法、通配符、常量
- 两时间比较