您好,想知道是否有办法通过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中的代码并输出答案。我该怎么做呢?