我正在尝试读取文件,我想读取文件的某些部分并跳过某些部分,直到我到达文件末尾。这就是我所拥有的,但我没有得到我想要的结果。这个想法是通读所有行并检查它是否以“CH”或“CL”开头,如果直到文件末尾才移动到下一行并存储所有符合条件的行
new BufferedReader (new FileReader ("c:\\demo5.properties\\"));
while(( br.readLine()) != null ){
if (br.readLine().startsWith("CH") || br.readLine().startsWith("CL")) {
buf = new StringBuffer();
buf.append( br.readLine());
while (br.readLine()!= null && !br.readLine().startsWith("#") && !br.readLine().contains("claimID")){
buf.append( br.readLine()).append( "\n" );
}
z = buf.toString();
System.out.println(z);
s3+= z;
}
br.readLine();
文件格式
CH.field
CH.field
CH.field
CH.field
CH.field
#CH.field
#CH.field
#CH.field
#CH.field
*********
**
*********
CL1.field
CL1.field
CL1.field
CL1.field
CL1.field
*****************
#Result.CL1.field
#Result.CL1.field
#Result.CL1.field
Result.CL1.field
*********
CL4.field
CL4.field
CL4.field
#CL4.field
#CL4.field
#CL4.field
***********
#Result.CL4
#Result.CL4
#Result.CL4
#Result.CL
Result.CL4
CL5.field
CL5.field
CL5.field
#CL5.field
#CL5.field
输出
CH.fieldCH.field
CL1.field#Result.CL1.field
CL4.field
CL4.field
#CL4.field
CL5.fieldCL5.field