tobackfurture 2010-01-25 17:41
浏览 224
已采纳

关于java流处理的问题,希望大家都来思考一下。谢谢拉

我有一个流对象(BufferedReader),包含如下信息。
Ethernet adapter 大网:

    Connection-specific DNS Suffix  . : xxxx.com 
    IP Address. . . . . . . . . . . . : 15.122.33.114 
    Subnet Mask . . . . . . . . . . . : 255.255.254.0 
    Default Gateway . . . . . . . . . : 10.121.32.11 

Ethernet adapter 小网:

    Connection-specific DNS Suffix  . : xxxx.com 
    IP Address. . . . . . . . . . . . : 15.121.32.114 
    Subnet Mask . . . . . . . . . . . : 255.255.252.0 
    Default Gateway . . . . . . . . . : 15.121.32.13 

我现在想把以上的信息包装成一个数组,数组中包的是单个网域对象。
如EthernetEntity对象有如下属性。String connDNS, String IPaddress,String SubMask,String DefaultGateway

帮忙解决哈。

  • 写回答

3条回答 默认 最新

  • CaiHuajiang 2010-01-25 18:50
    关注

    [code="java"] private List getEthernets() throws IOException {
    FileChannel fc = new FileInputStream(getClass().getResource("a.txt")
    .getFile()).getChannel();
    ByteBuffer bb = ByteBuffer.allocate((int) fc.size() + 1);
    fc.read(bb);
    bb.flip();
    fc.close();
    String[] arr = new String(bb.array()).split("Ethernet");
    List list = new ArrayList();
    for (String s : arr) {
    if (s.contains("adapter")) {
    EthernetEntity ee = new EthernetEntity();
    String[] ethernets = s.split("\n");
    for (int i = 0; i < ethernets.length; i++) {
    String[] info = ethernets[i].split(":");
    if (info[0].contains("Connection-specific DNS Suffix"))
    ee.setConnDNS(info[1].trim());
    if (info[0].contains("IP Address"))
    ee.setIPaddress(info[1].trim());
    if (info[0].contains("Subnet Mask"))
    ee.setSubMask(info[1].trim());
    if (info[0].contains("Default Gateway"))
    ee.setDefaultGateway(info[1].trim());
    }
    list.add(ee);
    }
    }
    return list;
    }[/code]

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog