我有一个txt文件,而一行是这样的:
"Execution Status: Pass"
我想带走价值:从这里传递。
我正在使用以下代码:
String patternString1 = "(Execution) (Status:) (.*)";
Pattern patt1 = Pattern.compile( patternString1 );
BufferedReader r = new BufferedReader(new FileReader( "c:\\abc.txt" ));
String line;
while ( (line = r.readLine()) != null ) {
String g11 = null;
Matcher m1 = patt1.matcher( line );
while ( m1.find() ) {
g11=m1.group(3);
System.out.println(g11+"HI1"); //Line1
}
System.out.println(g11+"HI1"); //Line2
}
当第1行给出期望的输出作为“ pass”时,我没有从第2行获得期望的输出。请你们中的任何一个能帮助我从循环中访问局部变量吗?
在方法开始时将字符串g11声明为局部变量
String g11=""; -- declare g11 as a local variable
String patternString1 = "(Execution) (Status:) (.*)";
Pattern patt1 = Pattern.compile(patternString1);
Add the rest of your code here.........
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句