我在當一個行是這樣的txt文件:如何使局部變量外循環訪問在java中
"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號線所賜爲「合格」我沒有收到從2號線 這個預期產量可能你的任何一個請幫我在期望的輸出從循環中訪問局部變量?
你在哪裏聲明'g11'開始的局部變量? – christopher
在內部while循環之外 – Abuzar
一個簡單的方法將簡單地使用'line.split(「:」);' –