以前,我们运行外部程序要用 Runtime.exec(..) ,现在有新方法了。
package maoxiang.examples.jdk15.lang;
import java.util.Map;
/**
* @author 毛翔
*
*/
public class DemoProcessBuilder {
public static void main(String[] args) {
ProcessBuilder pb = new ProcessBuilder("notepad.exe");
Map<String, String> env = pb.environment();
env.put("VAR1", "myValue");
env.remove("OTHERVAR");
env.put("VAR2", env.get("VAR1") + "suffix");
System.out.println(pb.directory().toString());
Process p = pb.start();
}
}
本文地址:http://com.8s8s.com/it/it14816.htm