java 文本解析成List<map>集合
interfacetime=2006-12-1100:37:38|ip=172.30.27.33|type=windows|patrolagenttime=2006-12...
interfacetime=2006-12-11 00:37:38|ip=172.30.27.33|type=windows|patrolagenttime=2006-12-11 00:37:35|NT_HEALTH/NT_HEALTH/DiskUsage=-999.999
interfacetime=2006-12-11 00:37:38|ip=172.30.27.33|type=windows|patrolagenttime=2006-12-11 00:37:38|NT_HEALTH/NT_HEALTH/MemoryUsage=-999.999
interfacetime=2006-12-11 00:37:38|ip=172.30.27.33|type=windows|patrolagenttime=2006-12-11 00:37:38|NT_HEALTH/NT_HEALTH/ProcessorUtilization=-999.999
把这种格式转换为list<map>集合.这个怎么做啊 展开
interfacetime=2006-12-11 00:37:38|ip=172.30.27.33|type=windows|patrolagenttime=2006-12-11 00:37:38|NT_HEALTH/NT_HEALTH/MemoryUsage=-999.999
interfacetime=2006-12-11 00:37:38|ip=172.30.27.33|type=windows|patrolagenttime=2006-12-11 00:37:38|NT_HEALTH/NT_HEALTH/ProcessorUtilization=-999.999
把这种格式转换为list<map>集合.这个怎么做啊 展开
展开全部
List<Map<String, String>> dataList = new ArrayList<Map<String, String>>();
Map<String, String> dataMap = new HashMap<String, String>();
dataMap.put("interfacetime", "2006-12-11 00:37:38");
dataMap.put("ip", "172.30.27.33");
dataMap.put("type", "windows");
dataMap.put("patrolagenttime", "2006-12-11 00:37:38");
dataMap.put("NT_HEALTH/NT_HEALTH/ProcessorUtilization", "-999.999");
//这里只是添加了一个map,你可以定义多个map,按照上面的格式,放入这个list就OK
dataList.add(dataMap);
展开全部
创建一个实体类:有interfacetime、ip、type等字段、创建一个LIst<map>类型的集合来保存数据;先将文件读出来保存到字符串变量里,然后使用split(“|”)方法分割字符串,再使用split("=")分割字符串
追问
切割做完了,感觉楼上的代码靠谱,吃完饭试试
追答
public static void main(String[] args) throws IOException {
List> list = new ArrayList>(0);
FileReader fr = new FileReader(new File("d:/aaaa.txt"));
BufferedReader br = new BufferedReader(fr);
String str = null;
StringBuilder sBuilder = new StringBuilder();
while ((str = br.readLine()) != null) {
Map map = new HashMap(0);
String[] s1 = str.split("|");
for (int i = 0; i map : list) {
for (String aa : map.keySet()) {
System.out.println(aa);
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询