Find string and print next lines until empty line
Solution 1:
On StackOverflow it is expected etiquette to post the code you have tried to write, so that answerers can focus on helping you with your specific mistakes, rather than asking for a from-scratch solution. Nevertheless, here you go:
import java.io.BufferedReader;
import java.io.FileReader;
public class SO {
public static void main(String[] args) throws Exception {
try (BufferedReader br = new BufferedReader(new FileReader("file.txt"))) {
boolean blank = false;
boolean found = false;
String line;
while ((line = br.readLine()) != null) {
if (line.strip().equals("")) {
blank = true;
found = false;
continue;
} else {
blank = false;
}
if (line.equals("USER1")) {
found = true;
continue;
}
if (!blank && found) {
System.out.println(line);
}
}
}
}
}