Packagecom. System.Runtime;Importjava.io.IOException;/*runtime The class class mainly represents the environment in which the application runs. GetRuntime () returns the running environment object for the current application. The EXEC (String command) executes the corresponding executable file according to the specified path. Freememory () returns the amount of idle memory in the Java virtual machine. Returns the maximum amount of memory that the Java virtual machine is attempting to use, in bytes maxmemory (). TotalMemory () Returns the total amount of memory in the Java virtual machine*//*Public class Runtimeuse {public static void main (string[] args) {Runtime RT = Runtime.getruntime ( ); System.out.println ("Returns the Environment object of the current application," +rt.getruntime ()); try {rt.exec ("C:\\windows\\system32\\calc"). EXE ");//Open a calculator} catch (IOException e) {e.printstacktrace (); } thread.sleep (3000); Process.destroy (); Returns the amount of free memory in a Java virtual machine. In bytes System.out.println ("Idle memory in the Java virtual machine," +rt.freememory ()); Returns the maximum amount of memory that the Java virtual machine is attempting to use. System.out.println ("The maximum amount of memory that the AVA virtual machine tries to use," +rt.maxmemory ()); TotalMemory () Returns the total amount of memory in the Java Virtual machine System.out.println ("Total memory in the Java Virtual machine," +rt.totalmemory ()); }}*///Open a program for 3 seconds and then close Public classRuntimeuse { Public Static voidMain (string[] args)throwsinterruptedexception {Runtime rt=Runtime.getruntime (); Try{Process PR=rt.exec ("C:\\windows\\system32\\calc. EXE "); Thread.Sleep (3000); Pr.destroy (); } Catch(IOException e) {//TODO auto-generated Catch blockE.printstacktrace (); } }}
Use of the Runtime class