取出一个TXT中的字符然后取出其中的数字问题。源码如下。不知道哪错了

zero12300 2013-03-22 10:30:56
package COM.LZJ;

import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.io.*;

public class SelectNum {

File file = null;
BufferedReader br = null;
List list = null;

Pattern p = null ;
public static void main(String[] args) {
new SelectNum().go();
}
public void go(){
try {
file = new File("d:\\123.txt");
br = new BufferedReader(new FileReader(file));
list = new ArrayList();
String str;
while((str = br.readLine())!=null){
list.add(str);
}
br.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException w){
w.printStackTrace();
}
for(Iterator i = list.iterator();i.hasNext();){

String re = "\\d+";
p = Pattern.compile(re);
Matcher m = p.matcher("i.next()&&(i.next())trim()");
while(m.find()){
System.out.println(m.group());
}
}
}
}

大神门帮忙看看吧 小弟在此感激不尽~
...全文
82 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
Matcher m = p.matcher("i.next()&&(i.next())trim()");
改成
Matcher m = p.matcher(i.next().toString);
踏地望星 2013-03-22
  • 打赏
  • 举报
回复
引用
Matcher m = p.matcher("i.next()&&(i.next())trim()");
出错了。。。 去看下API 改为: Matcher m = p.matcher(i.next().trim()); 是否能达到你要的效果

62,621

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧