J2se|window
An example uses the j2se5.0 Processbuilder class to perform an external program, which is more convenient than the runtime.exec and can set environment variables.
Package Com.kuaff.jdk5package;import Java.io.ioexception;import Java.io.inputstream;import java.util.ArrayList; Import Java.util.list;public class processbuildershow{public static list<string> getphysicaladdress () { Process p = null; Physical network card list list<string> address = new arraylist<string> (); try {//execute Ipconfig/all command p = new Processbuilder ("ipconfig", "/all"). Start (); catch (IOException E) {return address; } byte[] B = new byte[1024]; StringBuffer sb = new StringBuffer (); Read process output value InputStream in = P.getinputstream (); try {while (In.read (b) >0) {sb.append (new String (b)); } catch (IOException E1) {} finally {try { In.close (); catch (IOException E2) { }//below analysis output value, get physical nic String rtvalue = sb.substring (0); int i = Rtvalue.indexof ("Physical Address ...:"); while (i>0) {rtvalue = rtvalue.substring (i + "Physical address ...:". Length ()); Address.add (rtvalue.substring (0,18)); i = Rtvalue.indexof ("Physical Address ...:"); return to address; public static void Main (string[] args) {list<string> address = processbuildershow.getphysicaladdress (); for (String add:address) {System.out.printf ("Physical network card address:%s%n", add); } }}