Android读写配置文件

android 读写配置文件

基本上我们所有的数据均放在 /data/data/com.xxx.xxx目录下:

shared_prefs/ 放置简单的配置信息文件,文件格式为xxx.xml;


databases/ 放置数据库文件,文件名自己定义。


//SharedPreferences 文件读写

//读文件
SharedPreferences settings = this.getContext().getSharedPreferences(
				this.getClass().getName(), 0);
		string str = settings.getString("password", "");



//写文件
SharedPreferences settings = this.getContext().getSharedPreferences(
				this.getClass().getName(), 0);
		Editor editor = settings.edit();
		editor.putString("password", password);
		editor.commit();
		
//这里的 this.getClass().getName()是获得类名称。
//getSharedPreferences(String name, int mode);
//private static String strFile = "/data/data/com.entesi.wells/files/wells.properties";

//读文件
Properties properties = new Properties();
try {
	File fil=new File(strFile);
	if(!fil.exists())
	{
		fil.createNewFile();
		return false;
	}
	else
	{
		FileInputStream s = new FileInputStream(strFile);
		properties.load(s);
	}
} catch (Exception e) 
{
	e.printStackTrace();
	return false;
}

if ((String)properties.get("waittime")!=null)
	this.nWaitTime = Integer.parseInt((String)properties.get("waittime"));

//写文件
try {  
		FileOutputStream s = new FileOutputStream(strFile, false);  
		Properties properties = new Properties();
		
		File fil=new File(strFile);
		if(!fil.exists()){
			fil.createNewFile();
		}
		properties.setProperty("waittime", nWaitTime+"");
		
		properties.store(s, null); 
	} catch (Exception e){  
		e.printStackTrace();  
	} 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

杭州浪子

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值