如何使用java应用程序绑定Windows控制台应用程序?

我有一个可执行程序(.exe)用c ++编写并在Windows控制台上运行,我有一个java swing applecation,所以我希望我的java应用程序与控制台应用程序交互(发送输入和获取输出)。 但是怎么做?

你可以这样做

// Create the proccess in JAVA Process proc = Runtime.getRuntime().exec("Name of application"); // Receive outputs from another program inside Java by a stream InputStream ips = proc.getInputStream(); // Using the stream to get the messages from another program String output = ""; int c = 0; while ((c = ips.read()) != -1){ output+= (char)c; } //Inputs messages into another program OutputStream ops = proc.getOutputStream(); ops.write("an byte array"); 

您可以从Java程序中启动C ++程序,该程序允许您写入其标准输入,并读取其标准输出。 检查Runtime类。