import java.io.*;
import java.lang.reflect.method;
import com.sun.tools.javac.*;
public class runtimecode {
private static main javac = new main();
/**等待用?糨?入javacode,然後???g、?绦?*/
public static void main(string[] args) throws exception {
string code = "";
datainputstream bd = new datainputstream(system.in);
byte[] brray= new byte[200];
int i = bd.read(brray);
code = new string(brray,0,i);
run(compile(code));
system.out.print(code);
}
/**???gjavacode,返回?捍??n案物件*/
private synchronized static file compile(string code) throws exception {
file file;
//在用?舢?前文件目????建一???r?r代?a文件
file = file.createtempfile("javaruntime", ".java", new file(system.getproperty("user.dir")));
system.out.println(system.getproperty("user.dir"));
//?????m?c退出?r,?h除此?r?rjava原始?n案
//file.deleteonexit();
//?@得?n案名和??名字
string filename = file.getname();
string classname = getclassname(filename);
//?⒋??a??出到文件
printwriter out = new printwriter(new fileoutputstream(file));
// out.println("/**");
out.write("class "+classname+"{"+"public static void main(string[] args)"+"{");
out.write(code);
out.write("}}");
//?p?]文件流
out.flush();
out.close();
string[] args = new string[] { "-d", system.getproperty("user.dir"),filename };
//返回???g的???b代?a
int status = javac.compile(args);
system.out.println(status);
return file;
}
//
闽公网安备 35060202000074号