FileReader reader = new FileReader("f://file.TextGrid");
BufferedReader br = new BufferedReader(reader);
Pattern sizePattern = Pattern.compile("(^size)+(.)+[0-9]+");
Pattern xmPattern = Pattern.compile("(xm)(.)+(\\d+\\.)?\\d+");
String strText;
int lineIndex = 0;
while ((strText = br.readLine()) != null) {
Matcher sizeMatcher = sizePattern.matcher(strText);
Matcher xmMatcher = xmPattern.matcher(strText);
while(xmMatcher.find()){
if(xmMatcher.group() != null) {
for(int j = 0; j < xmMatcher.groupCount(); j++)
System.out.println(xmMatcher.group(j));
}
}
}
br.close();
reader.close();
输出结果是:
xmin = 0.000000
xm
0
只想要第一行,请问错误在那?估计是groupCount的问题,请指教,谢谢
BufferedReader br = new BufferedReader(reader);
Pattern sizePattern = Pattern.compile("(^size)+(.)+[0-9]+");
Pattern xmPattern = Pattern.compile("(xm)(.)+(\\d+\\.)?\\d+");
String strText;
int lineIndex = 0;
while ((strText = br.readLine()) != null) {
Matcher sizeMatcher = sizePattern.matcher(strText);
Matcher xmMatcher = xmPattern.matcher(strText);
while(xmMatcher.find()){
if(xmMatcher.group() != null) {
for(int j = 0; j < xmMatcher.groupCount(); j++)
System.out.println(xmMatcher.group(j));
}
}
}
br.close();
reader.close();
输出结果是:
xmin = 0.000000
xm
0
只想要第一行,请问错误在那?估计是groupCount的问题,请指教,谢谢
解决方案 »
- 求助:我想做一个要使用扫描仪的java桌面程序,请问需要什么类包?
- 求助:能否将一个Image类所包含的图像写入文件?
- 大家有没有这样的js树:可以动态添加节点的,但不用刷新整颗树,就像CSDN左侧那样
- 求助:servlet编程问题
- tom2005(快乐着) ( ) 大侠请来接分!!!!!!!!!1(真的好谢谢你!)
- 救命啊!谁帮我写一个getTable() 函数将查询结果返回到tA1!
- ie运行applet需要的最小的安装文件是??如何判断客户浏览器是否安装java支持?
- log4j配置文件的路径,我现在换了很多种写法,都没找到我的配置文件,请帮忙——Erazor
- java 与数据结构
- java程序,所有整数型数值全部转换成int型,这么写对吗
- excel上传数据内存溢出怎么办
- swing 多线程的问题
只要第一行
System.out.println(xmMatcher.group(0));
给j变成0了
一般group(0)代表整体匹配到的!