国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 學(xué)院 > 開(kāi)發(fā)設(shè)計(jì) > 正文

J2SE5.0新特性之ProcessBuilder

2019-11-18 11:54:11
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

  這個(gè)例子使用了J2SE5.0的PRocessBuilder類執(zhí)行外部的程序,相對(duì)于 Runtime.exec ,它更方便,可以設(shè)置環(huán)境變量等。這里使用它在windows下讀取物理網(wǎng)卡的地址
  
  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 getPhysicalAddress()
  {
  Process p = null;
  //物理網(wǎng)卡列表
  List address = new ArrayList();
  
  try
  {
  //執(zhí)行ipconfig /all命令
  p = new ProcessBuilder("ipconfig", "/all").start();
  }
  catch (IOException e)
  {
  return address;
  }
  byte[] b = new byte[1024];
  StringBuffer sb = new StringBuffer();
  //讀取進(jìn)程輸出值
  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)
  {
  }
  }
  //以下分析輸出值,得到物理網(wǎng)卡
  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 address;
  }
  public static void main(String[] args)
  {
  List address = ProcessBuilderShow.getPhysicalAddress();
  for(String add:address)
  {
  System.out.printf("物理網(wǎng)卡地址:%s%n", add);
  }
  }
  }

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 元江| 会理县| 临夏市| 托克托县| 喜德县| 滨海县| 遵义市| 伽师县| 白城市| 安龙县| 吴桥县| 石狮市| 五台县| 石泉县| 夏邑县| 五大连池市| 诸城市| 孝昌县| 交城县| 清原| 新建县| 仙游县| 平南县| 简阳市| 会昌县| 济阳县| 濮阳市| 宣威市| 淮南市| 清河县| 丹阳市| 延吉市| 寻乌县| 璧山县| 镇江市| 海林市| 闻喜县| 鄂伦春自治旗| 广水市| 孝昌县| 石狮市|