这应该真的很简单,但无论出于何种原因......
String line;
String question = "";
Question qObj = new Question();
line = br.readLine(); //points to where i am in the file!
if (line == null){
System.out.println("There was no question here. ");
System.exit(1);
} else if (line.isEmpty() || line.trim().equals("") || line.trim().equals("\n")) {
// do nothing, i don't want empty lines
} else {
question = line;
}
while ((line = br.readLine())!= null){
if (line.indexOf(LoadFromDb.ANSWER_BEGIN) == 0){
dealWithAnswer(br, qObj);
qObj.setQuestion(question);
break;
} else {
if (!line.isEmpty()){
question += "\n" + line.trim();
}
}
如果上面的代码读取的第一行只是一个空行,那么它将空行添加到 line 对象,它不会跳过它。任何想法为什么?