我想从txt文件中获取Name,Surname和birthdate 这就是我所拥有的
Scanner scFile = new Scanner (new File("BirthDates.txt"));
String Name;
int BirthDates = 0;
String Line = null;
while(scFile.hasNext())
{
Line = scFile.nextLine();
Scanner scLine = new Scanner(Line).useDelimiter("#");
Name = scLine.next();
BirthDates = scLine.nextInt();
scLine.close();
System.out.println(Name + BirthDates);
}
scFile.close();
答案 0 :(得分:1)
问题来源:
在这一行:BirthDates = scLine.nextInt();
,您尝试将出生日设为int
,但是您在#
Jackson
之后读取了第二个值。
解决方案:
获取全名,然后获得您的出生日:
Name = scLine.next();
secondeName = scLine.next();
BirthDates = scLine.nextInt();
有关详情,请参阅this