Reputation: 831
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);
}
the text file that is read is
111
John Adams
1
0
.
222
Paul Brake
2
1
.
333
George Clarke
2
2
.
4
its showing an inputmismatch exception
Upvotes: 0
Views: 155
Reputation: 79838
Your line occ=k.nextLine();
will be reading the newline character after the previous integer, instead of reading the line of text that you want it to read. You need to insert an extra call to k.nextLine()
before this. You'll need the same when you read the dot at the end of each Room
too.
Upvotes: 3