这是一个应该解决问题的最小答案。我确实将代码减少到必要的部分,因为我需要自己测试它,而且我无法访问你使用过的类。
在提问时,您应该尽可能将问题中的代码设为minimal,以便重新创建。
public static void main(String args[]) {
List lines = new ArrayList();
lines.add("This is first line.");
lines.add("This is second line.");
lines.add(" ");
lines.add(" ");
lines.add(" ");
lines.add(" ");
lines.add("This is third printed line.");
lines.add(" ");
lines.add("This is fourth printed line.");
lines.add(" ");
lines.add(" ");
lines.add(" ");
lines.add("#ACC004342-123");
lines.add(" ");
lines.add(" ");
lines.add(" ");
lines.add(" ");
lines.add(" ");
lines.add(" ");
lines.add("More information:");
lines.add("This is fifth printed line.");
lines.add("#ACC004342-123");
lines.add("");
lines.add("This is Sixth printed line.");
lines.add("Some information goes here.");
//count empty lines
int emptyLineCounter = 0;
for (final String line : lines) {
//when empty line increment counter, else reset counter
if(line.trim().length() == 0)
emptyLineCounter++;
else
emptyLineCounter = 0;
//when more then 2 empty lines are encountered move ignore line
if(emptyLineCounter <= 2)
System.out.println(line); //add line to document
}
}