Sectionがないの場合

package co.test;import java.io.File;import java.io.FileInputStream;import java.io.InputStream;import java.util.Properties;import android.content.Context;public class IniReaderNoSection {public Properties properties = null;/** * ファイルのアドレス---->res/raw/**.ini <br> * resourceId--->R.raw.cc *  */public IniReaderNoSection(Context context, int resourceId) {InputStream inputStream = context.getResources().openRawResource(resourceId);try {properties = new Properties();properties.load(inputStream);} catch (Exception ex) {ex.printStackTrace();}}/** * ファイルのアドレス---->例えば、SD存储卡 *  */public IniReaderNoSection(String filename) {File file = new File(filename);try {properties = new Properties();properties.load(new FileInputStream(file));} catch (Exception ex) {ex.printStackTrace();}}public String getIniKey(String key) {if (properties.containsKey(key) == false) {return null;}return String.valueOf(properties.get(key));}}

Sectionがありの場合

package co.test;import java.io.BufferedReader;import java.io.FileReader;import java.io.IOException;import java.util.HashMap;import java.util.Map;import java.util.Properties;public class IniReaderHasSection {private Map<String, Properties> sections;private String secion;private Properties properties;/** * ファイルのアドレス---->例えば、SD存储卡 *  */public IniReaderHasSection(String filename) throws IOException {sections = new HashMap<String, Properties>();BufferedReader reader = new BufferedReader(new FileReader(filename));read(reader);reader.close();}private void read(BufferedReader reader) throws IOException {String line;while ((line = reader.readLine()) != null) {parseLine(line);}}private void parseLine(String line) {line = line.trim();if (line.matches("\\[.*\\]") == true) {secion = line.replaceFirst("\\[(.*)\\]", "$1");properties = new Properties();sections.put(secion, properties);} else if (line.matches(".*=.*") == true) {if (properties != null) {int i = line.indexOf('=');String name = line.substring(0, i);String value = line.substring(i + 1);properties.setProperty(name, value);}}}public String getValue(String section, String name) {Properties p = sections.get(section);if (p == null) {return null;}String value = p.getProperty(name);return value;}}


更多相关文章

  1. 代码中设置drawableleft
  2. android 3.0 隐藏 系统标题栏
  3. Android开发中activity切换动画的实现
  4. Android(安卓)学习 笔记_05. 文件下载
  5. Android中直播视频技术探究之—摄像头Camera视频源数据采集解析
  6. 技术博客汇总
  7. android 2.3 wifi (一)
  8. AndRoid Notification的清空和修改
  9. Android中的Chronometer

随机推荐

  1. android评分条RatingBar自定义设置
  2. Android五大布局介绍&属性设置大全
  3. Android 开发艺术探索读书笔记 10 -- And
  4. 使用jQuery Mobile和Phone Gap开发Androi
  5. Android图形基础
  6. cocos2d-x3.2 在Windows下打包Android平
  7. Android的ImageView填充方式
  8. 通过命令行管理AVD
  9. pc 与 android webrtc 通信的研究
  10. 【移动生活】Google项目副总裁安迪·鲁宾