Import java.io. *; import java.lang.reflect.method; import com.sun.tools.javac. *;
Public class runtimecode {
private static Main javac = new Main (); / ** javacode waiting for user input, and then compile, execute * / 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); system.out.print (Code);
} / ** Compile JavaCode, return to the Speech file * / private synchronized static file compile (String code) throws exception {file file; // Create a temporary code file File = file.createTempfile ("Javaruntime" in the user's current file directory , ".java", new file (System.GetProperty ("user.dir"))); system.get.println ("user.dir")); // Delete this when the virtual machine exits Temporary Java Original Archive //file.deleteOxit (); // Get file names and class name string filename = file.getname (); string classname = getClassName (filename); // Output code to file print = new printwriter (new PrintWriter FileOutputStream (file)); // out.println ("/ **"); Out.write ("Class" ClassName "{" "public static void main (string [] args)" "{"); Out.write (code); out.write ("}}"); // Turns the file stream out.flush (); out.close (); string [] args = new string [] {"-d", System, SYSTEM .GetProperty ("User.dir"), filename}; // Returns Compile Status Code Int Status = JavaC.Compile (Args); System.out.Println (status); Return File; } // Run Private Static Synchronized Void Run (File File) THROWS Exception {String FileName = file.getname (); String ClassName = getClassName (filename); // Delete this temporarily compiled class file NEW when virtual machine exits File (file.getParent (), classname ".class"). DeleteOnexit (); try {class cls = class.forname (classname); // Mapping main method Method main = cls.getMethod ("main", new class [] {String []. Class}); // Execute the main method main.invoke (null, new object [] {new string [0]});