Need help wit reading txt file into input.
im trying to read a txt file into an array so i can process
in the txt file it has a name followed by a space then a number
eg ben 21364
every thing complies it when i run the code it throw in arrayOUtOFBOuNDS
exceptions
here is the code
Code:
public class RunMethods
{
//attributes
Boy [] boys = new Boy[0];
private Girl [] girls;
Scanner keyboard = new Scanner(System.in);
//constructor
public RunMethods()
{
}
//get set methods
public void fileReadIn()
{
int k = 0;
try
{
Scanner input = new Scanner(new FileInputStream("boynames.txt"));
while(input.hasNext())
{
String line = input.nextLine();
String [] parts = line.split(" ");
boys[k] = new Boy(parts[0],Integer.parseInt(parts[1]));
k++;
}
input.close();
}
catch(FileNotFoundException fnfe)
{
System.out.printf("Problem opening file....\n");
System.exit(0);
}
for(int i = 0;i < boys.length;i++)
{
System.out.printf("%s\n",boys[i].toString());
}
}
}
this is the line it doesnt like
Code:
boys[k] = new Boy(parts[0],Integer.parseInt(parts[1]));
any help would be much appreciated and i like to
thank every one in advance who does help
:)