Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.io.IOException;
import java.io.Reader;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;

public class Main {
    public static void main(String[] args) {
        String scriptFileName = "c:/test.js";
        Path scriptPath = Paths.get(scriptFileName);
        ScriptEngineManager manager = new ScriptEngineManager();
        ScriptEngine engine = manager.getEngineByName("JavaScript");
        try {
            Reader scriptReader = Files.newBufferedReader(scriptPath);
            engine.eval(scriptReader);
        } catch (IOException | ScriptException e) {
            e.printStackTrace();
        }
    }
}