解决方案 »
- 将图片转换为字节方式存储到Byte数组中
- java解压ZIP,请大虾们指点
- struts+spring+hibernate各有什么好处
- 关于java调用系统默认邮件程序的问题
- 有一个jar文件,我用rar解压后替换其中一个class,然后在生成jar.怎么就不能用了??
- 关于JAVA中的图形问题?图形高手请进!
- 如果让一个JTable的一个单元格处于编辑状态呢?
- 求java访问sql server的简单查询例子代码。
- 谁有weblogic6.0的crack文件?没人有吗?
- 请教高手,怎样让java的应用程序在后台运行,图标在右下角状态栏?
- 一个Sql问题
- 大家说说吧,拿到一个比较大的 工程代码。如何读。
如果txt中文本符合xml语法的话,也可以DOM方式读取各个节点的值。
String s="<score> 7</score> <title> My View on Fake Commodities</title><content>Last month I bought a pair of shoes from a rather famous shoe-shop. But this month it has occurred several small seams.</content>";
Matcher m=Pattern.compile("<(\\w+)>(.+?)</\\1>").matcher(s);
Map<String,Integer> int_map=new HashMap<String, Integer>();
Map<String,String> str_map=new HashMap<String, String>();
while(m.find()){
if(m.group(2).trim().matches("\\d+")){
int_map.put(m.group(1), Integer.parseInt(m.group(2).trim()));
}
else{
str_map.put(m.group(1), m.group(2));
}
}
System.out.println(int_map);
System.out.println(str_map);
"(?s)<(\\w+)>(.+?)</\\1>"