JDK 1.5 Characteristics Using Example 7 - Run External Program

xiaoxiao2021-03-06  78

Previously, we run external programs to use runtime.exec (..), now there is a new method.

Package maoxiang.examples.jdk15.lang;

Import java.util.map;

/ **

* @Author Mao Xiang

*

* /

Public class demoprocessBuilder {

Public static void main (String [] args) {

ProcessBuilder PB = New ProcessBuilder ("NOTEPAD.EXE");

Map 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 ();

}

}

转载请注明原文地址:https://www.9cbs.com/read-108562.html

New Post(0)