Hi, I am really struggling with a bufferedReader method i am trying to implement. I have to read text from a file like this :
Poland
Franciszek,Smuda,63,2009
1,GK,Wojciech,Szczesny,22,11,0
2,DF,Sebastian,Boenisch,25,9,0
3,DF,Grzegorz,Wojtkowiak,28,19,0
4,DF,Marcin,Kaminski,20,3,0
5,MF,Dariusz,Dudka,28,65,2
6,MF,Adam,Matuszczyk,23,20,1
and store it in an array of objects (mine being an array of Player objects which stores information on the players for the polish football team).
Now I have created the method in a different class called the group class. The specification asks to create a readFromFile() method which will read the above text and output it.
The error I receive is java.lang.NumberFormatException: For input string: "Poland"
I believe it is because I am maybe parsing my types wrong but i an confused and unsure.
My method looks like this:
// Buffered Reader Method
public void readFromFile(String f){
Player[] players = null;
try {
BufferedReader br = new BufferedReader(new FileReader(new File("data.txt")));
int size = Integer.parseInt(br.readLine());
players = new Player[size];
String newLine = br.readLine();
int count = 0;
while(newLine != null){
StringTokenizer st = new StringTokenizer(newLine, ",,,,,,");
String desc = st.nextToken();
int squadNumber = Integer.parseInt(st.nextToken());
String position = (st.nextToken());
String firstName = (st.nextToken());
String surname = (st.nextToken());
int noOfCaps = Integer.parseInt(st.nextToken());
int goalsScored = Integer.parseInt(st.nextToken());
boolean isCaptain = Boolean.parseBoolean(st.nextToken());
int age = Integer.parseInt(st.nextToken());
players[count] = new Player(squadNumber, position, firstName, surname, noOfCaps, goalsScored, isCaptain, age);
count ++;
newLine = br.readLine();
}
br.close();
} catch (Exception ex) {
System.out.println(ex.toString());
}
for (int i = 0; i < players.length; i++){
System.out.println(players[i].toString());
}
}
Any help would be greatly appreciated.