try
{
File f=new File(fname);
Scanner k=new Scanner(f);
Scanner k3=new Scanner(System.in);
int drNr;
String occ;
int adl;
int child;
while(k.hasNext())
{
drNr=k.nextInt();
occ=k.nextLine();
adl=k.nextInt();
child=k.nextInt();
k.nextLine();
Room r=new Room(drNr,occ,adl,child);
roomList.add(r);
}
k.close();
}
catch(FileNotFoundException e)
{
System.out.println("file not found");
}
catch(Exception e)
{
System.out.println(e);
}
读取的文本文件是
111
John Adams
1
0
.
222
Paul Brake
2
1
.
333
George Clarke
2
2
.
4
它显示输入不匹配异常