日期:2014-05-16 浏览次数:20328 次
yum install java-1.6.0-sun.x86_64 java-1.6.0-sun-devel.x86_64
import java.io.FileReader; import javax.script.ScriptEngine; import javax.script.ScriptEngineManager; public class RunScriptFile { public static void main(String[] args) { ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine engine = manager.getEngineByName("js"); try { FileReader reader = new FileReader("testFile.js"); engine.eval(reader); reader.close(); } catch (Exception e) { e.printStackTrace(); } } }
function add(a, b) { c = a + b; return c; } result = add (10, 5); print ('Result = ' + result);
javac RunScriptFile.java
java RunScriptFile