1 回答

TA贡献1802条经验 获得超6个赞
您的文本文件可能包含空行。您可以删除文本文件中的新行,更改文本文件的创建方式,或者在阅读文本文件时跳过空行。
这是跳过空行的方法:
while (sc.hasNextLine()) {
String temp = sc.nextLine();
if (temp.equals("")) { continue; } // <--- notice this line
String[] tempArray = temp.split(" % ");
System.out.println(tempArray[0]);
// Splitting the array into its appropriate temp variables
double payCheckAmount = Double.parseDouble(tempArray[0]);
String paycheckDate = tempArray[1];
String description = tempArray[2];
boolean payCheckSplit = Boolean.parseBoolean(tempArray[3]);
double amountUnSplit = Double.parseDouble(tempArray[4]);
}
}
添加回答
举报