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());
}
}
}
}
大神门帮忙看看吧 小弟在此感激不尽~
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());
}
}
}
}
大神门帮忙看看吧 小弟在此感激不尽~
解决方案 »
- 读入Shp文件,文件头的构造问题
- 这个程序要加入什么Main语句才能正常编译解释执行
- 中文字符该怎样处理?
- TextField怎样限制只能输入数字?
- java.lang.OutOfMemoryError
- 二维数组排序
- 各位大侠: 能否列出常用的、需要熟记的类及方法吗?
- 我要创建一个模式对话框,但是......
- 急:请教FileDialog类的setFilenameFilter()方法如何使用?
- 我刚学Java,用Javac编译一个例程没问题,但一用Java运行就出错:Exception in the thread "main" java.lang.NoClassDefFoundError: Welcome(rolt1)[Java]
- 多态
- java JTree选中某个叶子节点,回车,相当于双击事件
去看下API
改为:
Matcher m = p.matcher(i.next().trim());
是否能达到你要的效果
改成
Matcher m = p.matcher(i.next().toString);