package src; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.BufferedReader; import javax.tools.JavaCompiler; import javax.tools.ToolProvider; public class Demo01 { public static void main(String[] args) throws IOException { // 动态编译 JavaCompiler comp = ToolProvider.getSystemJavaCompiler(); int result=comp.run(null, null, null, "D:\\codes\\javaProjects\\test\\Test.java"); System.out.println(result==0?"运行成功":"运行失败"); Runtime run = Runtime.getRuntime(); Process process= run.exec("java -cp D:/codes/javaProjects/test Test"); InputStream in= process.getInputStream(); BufferedReader reader = new BufferedReader(new InputStreamReader(in)); String info = ""; while((info=reader.readLine())!=null) { System.out.println(info); } } }
标签:info,动态,java,编译,run,io,import,null From: https://www.cnblogs.com/Mengchangxin/p/17525540.html