Hi all,
I'm struggling with a challenge on new learnings about reading and writing from a txt file.
Now I have just learnt about the Scanner class and i can usedelimiter (",") to create tokens. But what if the txt file has a heading before each token on the first line, how do you check that what you want it to say and what it does say are true and therefore go on to next line which are where the tokens are. I do admit this is homework but i have spent a full day (which i haven't got) on one question. please somebody help me.
This is what i have managed so far but i know im wrong, my first confusion is how to get on to another line after the header is true.
The second confusion is how to end program safely if false.
This is all being done in a try catch finally statement .
the txt file reads like this
Pool A
England,3,0,1,2 ,0
Samoa,1,0,3,0,1
South Africa,4,0,0,3, 0
Tonga,2,0,2,0,1
USA,0,0,4,0,1
Any ideas??
Brendan
I'm struggling with a challenge on new learnings about reading and writing from a txt file.
Now I have just learnt about the Scanner class and i can usedelimiter (",") to create tokens. But what if the txt file has a heading before each token on the first line, how do you check that what you want it to say and what it does say are true and therefore go on to next line which are where the tokens are. I do admit this is homework but i have spent a full day (which i haven't got) on one question. please somebody help me.
Code:
/** * Prompts the user for the name of the text file that * contains the results of the teams in this pool. The * method uses this file to set the results of the teams. */ public void loadTeams() { OUDialog.alert("Please Select a file containing results for : " + this.getPoolName()); String pathName = OUFileChooser.getFilename(); File aFile = new File(pathName); BufferedReader bufferedFileReader = null; try { Scanner lineScanner; bufferedFileReader = new BufferedReader(new FileReader(aFile); String currentLine = bufferedFileReader.readLine() if (currentLine.equals(this.getPoolName()); { currentLine = bufferedFileReader.newLine() }
The second confusion is how to end program safely if false.
This is all being done in a try catch finally statement .
the txt file reads like this
Pool A
England,3,0,1,2 ,0
Samoa,1,0,3,0,1
South Africa,4,0,0,3, 0
Tonga,2,0,2,0,1
USA,0,0,4,0,1
Any ideas??
Brendan
Comment