Is there a simpler way to do parsing in Java on Android? -


i'm having difficulty performing should simple task. let's have text file states:

a = b 

i want program read file , output "b" whenever user inputs "a". in python or c++ can accomplish in around 7 lines or less.

however, i'm having difficulty finding simple way on android. example, 1 sample found here on had 900 lines in 6 files.

is there simple way parse file , return variable on android missing?

as long you're happy thea = b format used in properties files, 99% of way goal

properties properties = new properties(); try {     properties.load(new fileinputstream(filename)); } catch (ioexception e) {     // file missing or not in 'a = b' format } 

the, having got variable key containing string "a" user, result of properties.getproperty ( key ) equal "b" if file contains line a = b. i'm pretty sure need more in c++ load map file , handle escaping , character encoding issues.

if properties held in text file called mappings.properties in assets folder of android project rather in user's file system, @ this:

    final assetmanager = getresources().getassets();     final properties properties = new properties();      try {         properties.load( am.open("mappings.properties"));     } catch (ioexception e) {         // file missing or not in 'a = b' format     } 

this next bit borrowed android tutorial show toast message 'b' in if 'a' entered in edit box. maybe here line count from, setting gui xml files , adding listeners in java verbose compared other languages. that's due java , xml syntax rather virtual machine.

    final edittext edittext = (edittext) findviewbyid(r.id.edittext);      edittext.setonkeylistener(new onkeylistener() {         @override         public boolean onkey(view v, int keycode, keyevent event) {             // if event key-down event on "enter" button             if ((event.getaction() == keyevent.action_down) &&                 (keycode == keyevent.keycode_enter)) {               // perform action on key press               toast.maketext(yourouterviewclass.this,                    properties.getproperty(edittext.gettext().tostring()),                   toast.length_short).show();               return true;             }             return false;         }     }); 

Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -