Java 调用C++可执行程序 发表于 2016-11-17 如何调用 简单测试 如何调用123456789101112131415161718192021import java.lang.ProcessBuilder; public class TestCallForExe { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub System.out.println("hello world!"); try { ProcessBuilder proc = new ProcessBuilder("/a.out", "testfile"); proc.start(); } catch (Exception e) { System.out.println("Error executing notepad."); } //System.out.println("Goodbye world!"); }} 简单测试123456789101112131415161718#include "iostream"#include "fstream" using namespace std; int main(int argc, char *argv[]){ for (int i = 0; i < argc; i++) { cout<<"args: "<<i<<" :"<<argv[i]<<endl; } ofstream f1; f1.open("./write_test.txt"); for (int i = 0; i < argc; i++) { f1<<"args: "<<i<<" :"<<argv[i]<<endl; } f1<<"hello world!"<<endl; f1.close(); return 0;}