我有一个流对象(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
帮忙解决哈。
[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]
按行解析嘛,不算难的
lz刚发过的呀
先按行读取到一个array中(记住trim哦) 再按照我刚回复的方法处理