如何使用Java在文本文件的两行之间获取文本? 我尝试这样做,但它不起作用:
Attempt to invoke virtual method 'android.support.v7.app.AlertDialog android.support.v7.app.AlertDialog$Builder.create()' on a null object reference
答案 0 :(得分:1)
更新回答
使用正则表达式
String pattern = "([\\s\\S]*?)(!!!Error deploying file)";
上述模式的解释。
示例代码:
String line = "!!!Error deploying file order\\POST_ORDER_UpdateTaxAmountCurrInCo.sql at 22-JUL-16 08:07:Chathura aBhanakana1!!!Error deploying file order\\POST_ORDER_UpdateTaxAmountChathura aBhanakana1AAAAA !!!Error deploying file order\\POST";
String pattern = "([\\s\\S]*?)(!!!Error deploying file)";
// Create a Pattern object
Pattern r = Pattern.compile(pattern);
// Now create matcher object.
Matcher m = r.matcher(line);
while (m.find( )) {
String str = m.group(1);
if(str != null && !str.isEmpty()){
System.out.println("Found value: " + str );
}
}
输出
使用拆分方法
示例代码:
String line = "!!!Error deploying file order\\POST_ORDER_UpdateTaxAmountCurrInCo.sql at 22-JUL-16 08:07:Chathura aBhanakana1!!!Error deploying file order\\POST_ORDER_UpdateTaxAmountChathura aBhanakana1AAAAA !!!Error deploying file order\\POST";
for (String retval: line.split("!!!Error deploying file")){
System.out.println(retval);
}
输出:
1 ) order\POST_ORDER_UpdateTaxAmountCurrInCo.sql at 22-JUL-16 08:07:Chathura aBhanakana1
2) order\POST_ORDER_UpdateTaxAmountChathura aBhanakana1AAAAA
3) order\POST