"a":"12345","b" : "2432334"
"a":"86543","b" : "4345534"
"a":"74564","b" : "4351234"
"a":"52454","b" : "6443534"
這是一個txt
文件,我想讀的文本文件和打印對應於「B」僅數即2432334,4345534,4351234,6443534
在Java中,從文本文件中讀取
Pattern p = Pattern.compile("\\b\\b", Pattern.CASE_INSENSITIVE);
while ((line = bf.readLine()) != null) {
linecount++;
Matcher m = p.matcher(line);
while (m.find()) {
int start = m.start(0);
int end = m.end(0);
/*System.out.println("Word was found at position " +
m.start() + " on line " + linecount);*/
System.out.println(line.substring(start, end));
}
}
讓我們瞭解您已經嘗試過。 –
歡迎!看看[如何提出問題](http://stackoverflow.com/help/how-to-ask)。你有什麼嘗試?什麼不起作用?你讀過什麼? – dantiston