[英]Append a specific line BufferedReader java
我想在包含例如“Result”的 BufferedReader 中找到特定行,並將整行存儲在字符串變量中,然后打印出字符串。 有什么辦法嗎?
try {
String toFind = "Result";
String line = null;
StringBuilder buffer = new StringBuilder();
while ((line = reader.readLine()) != null) {
if (line.indexOf(toFind) > -1) { // can also use contains()
buffer.append(line);
buffer.append('\n');
}
}
// ... Print the buffer like that, or by calling a utility method
System.out.println(buffer);
} finally {
reader.close();// wrap in try-catch for any IOE
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.