Back to project page ScienceQuiz.
The source code is released under:
GNU General Public License
If you think the Android project ScienceQuiz listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.finger.sciencequiz; /*from w w w . ja v a2 s . c o m*/ import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStreamReader; import java.util.HashMap; import android.content.Context; import android.util.Log; public class ConfigReader { public static String LOG_TAG = "ConfigReader"; public ConfigReader (String path, Context context) { this.Path = path; } public String Path; protected Context context; public HashMap<String, String> Read () { return Read (Path, context); } public static HashMap<String, String> Read (String path, Context context) { HashMap<String, String> cfg = new HashMap<String, String> (); try { InputStreamReader is = new InputStreamReader (context.getAssets () .open (path)); BufferedReader br = new BufferedReader (is); int lnNum = 1; String ln, key, val; while ((ln = br.readLine ()) != null) { ln = ln.trim (); if (!(ln.length () < 1 || ln.charAt (0) == 35)) { int idx = ln.indexOf ("="); try { key = ln.substring (0, idx); val = ln.substring (idx + 1, ln.length ()); cfg.put (key, val); } catch (IndexOutOfBoundsException e) { Log.w (LOG_TAG, path + ": Invalid option in line " + lnNum); } } lnNum++; } br.close (); } catch (FileNotFoundException e) { Log.e (LOG_TAG, "Config file not found: " + path); } catch (IOException e) { e.printStackTrace (); } return cfg; } }