Run contents of string in java -
this question has answer here:
- run piece of code contained in string 7 answers
lets have string: string run = "system.out.println\(\"hello\"\)"
. want run in string output hello
in console. maybe there method string.run()?
try beanshell , build app jar library.
import bsh.interpreter; private void runstring(string code){ interpreter interpreter = new interpreter(); try { interpreter.set("context", this);//set variable, can refer directly string interpreter.eval(code);//execute code } catch (exception e){//handle exception e.printstacktrace(); } }
Comments
Post a Comment