通过Java在txt文件中执行表达式

时间:2016-12-03 01:03:55

标签: java file expression

您好,想知道是否有办法通过Java从文本文件中执行一行代码。

例如,假设我有一个文本文件,并在该文本文件中包含一个表达式

int a = 1;
int b = 2;
int c;
c = a + b;

所以在我的主类中,我有一个文件对象,它执行try / catch

File file = new File("test.txt");

try {

    //code here

}catch (FileNotFoundException e) {
    System.err.format("File does not exist \n");
}

我的目标是运行test.txt中的代码并输出答案。我该怎么做呢?

0 个答案:

没有答案