在我的程序的一部分中,我正在读取包含"ua, "
并将它们设置为等于我想要处理的行数的行。我想使用数组来使这个灵活到我想要的多行。
这就是它如何使用 4 行
而不是有多个 else if 语句,我想简化它,以便我可以定义一些我想要处理的行,而不必编辑这部分
try (BufferedReader br = new BufferedReader(new FileReader(f.getAbsolutePath()))) {
String line1 = null, line2 = null, line3 = null, line4 = null, line = null;
boolean firstLineMet = false;
boolean secondLineMet = false;
boolean thirdLineMet = false;
while ((line = br.readLine()) != null) {
if (line.contains("ua, ")) {
if (!firstLineMet) {
line1 = line;
firstLineMet = true;
} else if (!secondLineMet) {
line2 = line;
secondLineMet = true;
} else if (!thirdLineMet) {
line3 = line;
thirdLineMet = true;
} else {
line4 = line;
ProcessLines(uaCount, line1, line2, line3, line4);
line1 = line2;
line2 = line3;
line3 = line4;
}
}
}
}