当我尝试测试文件读取时,出现堆栈溢出错误。我知道为什么会这样,但我不知道为什么它会在我的程序中发生以及如何解决它。这是我的主要,加载方法,显示方法和文件:
public static void main(String[] args)
{
try
{
loadEmployeesFromFile("employees.txt");
displayEmployees();
}catch (FileNotFoundException e)
{
System.err.println("File error: " + e.getMessage());
}catch (IOException e)
{
System.err.println("IO error: " + e.getMessage());
}
}
private static void loadEmployeesFromFile(String filename) throws IOException {
try (Scanner fin = new Scanner(new File(filename));)
{
String employeeRecord;
String fields[];
while (fin.hasNext())
{
employeeRecord = fin.nextLine();
fields = employeeRecord.split(",");
switch (fields[0]) {
case "F":
staff[numberOfRecords] = new FullTime(Double.parseDouble(fields[1]), fields[2], fields[3]);
break;
case "P":
staff[numberOfRecords] = new PartTime(Double.parseDouble(fields[2]), Double.parseDouble(fields[3]), fields[4], fields[5]);
break;
case "I":
staff[numberOfRecords] = new Intern(fields[1], fields[2]);
break;
}
numberOfRecords++;
}// end while
}
}
private static void displayEmployees()
{
for (int i = 0; i <= numberOfRecords - 1; i++)
{
System.out.println(staff[i]);
}
}
I,i1First,i1Last
楼65000.0,ft1First,ft1Last
P,13.5,50.0,pt1First,pt1Last
楼55000.0,ft2First,ft2Last
P,20.0,40.0,pt2First,pt2Last
答案 0 :(得分:1)
您已检查bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
"~/Scripts/jquery-{version}.js"));
bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
"~/Scripts/jquery.validate*",
"~/Scripts/jquery.unobtrusive-ajax.min.js"));
但尚未执行while(fin.hasNext())
,因此迭代器永远不会前进
尝试做
fin.next()
希望这有帮助!
祝你好运!