读写ini文件 java

来源:互联网 发布:钉钉软件使用说明 编辑:程序博客网 时间:2024/05/17 03:02

1、设置变量

String configpath = "/mnt/sdcard/policenavi/Config1/Config1.ini";FileInputStream fis = null; // 读OutputStream fos ;Properties pp;


2、初始化并加载读取的文件

pp = new Properties();fis = new FileInputStream(configpath);pp.load(fis);


 

3、获取ini信息

String GPSvalue = pp.get("Gps_device").toString();// 获取配置文件的Gps_device字段的信息,既它=号后面的数据String Soundvalue = pp.get("Sound").toString();// 同上String SmsSountvalue = pp.get("SmsSount").toString();// 同上String PhoneSountvalue = pp.get("PhoneSount").toString();// 同上


上面就获得了ini文件信息

写ini文件也可用此类方法,但是准确度不是很高,原来的ini文件顺序发生改变,还添加了头标示,但是这些不影响具体的读取、写入,对于较严格的格式要求,不提倡这种方法

 

写文件:跟上面衔接

fos=new FileOutputStream(configpath);//加载读取文件流pp.setProperty("Sound", "trunoff");// 修改值pp.store(fos, null);//修改值fos.close();


 

这就是一个简单的读取和写入ini文件的操作
原创粉丝点击